Skip to content

[SVLS-10205] fix(appsec): replace unmaintained multipart with multer - #1542

Open
litianningdatadog wants to merge 1 commit into
mainfrom
tianning.li/SVLS-10205
Open

litianningdatadog wants to merge 1 commit into
mainfrom
tianning.li/SVLS-10205

Conversation

@litianningdatadog

@litianningdatadog litianningdatadog commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem

AppSec parses multipart/form-data request bodies with multipart 0.18. That crate is unmaintained (RUSTSEC-2023-0050), and deny.toml ignored the advisory with no replacement planned.

Cause

multipart has had no release since 2021. It also pulls in buf_redux, mime_guess, quick-error, safemem, twoway and unicase.

This PR

  • Replaces multipart with multer 3.1 and removes the RUSTSEC-2023-0050 ignore from deny.toml.
  • multer only has an async API. read_multipart_fields puts the in-memory body into a single-chunk stream and drives it with futures::executor::block_on. The stream is always ready, so the call never waits.
  • Fields are collected before they are parsed. A nested multipart field recurses into read_multipart_fields, and block_on cannot be nested.
  • Enables the executor feature of futures. futures-executor was already in the dependency tree.
  • If the body ends inside the final field (before its closing boundary), that field's partial data is still analyzed, as multipart did. multer returns IncompleteFieldData and discards the buffered bytes, so truncated_field_data takes the data after that part's headers from the raw body. Truncation is still logged at WARN, as before.

Behavior changes:

  • A field with no name in Content-Disposition is skipped, and parsing continues. multipart stopped at that field and dropped every field after it.
  • A field with an invalid Content-Type is parsed as text/plain. multipart stopped at that field.
  • A quoted name containing ; (for example name="a;b") is kept whole. multipart cut it at the ;.
  • A value containing the boundary text without a preceding CRLF (for example x--By with boundary B) is kept whole. multipart cut the value there and stopped.
  • Whitespace after a boundary line (RFC 2046 transport padding) is accepted. multipart rejected the body.

A differential run of both crates on 26 bodies found these as the only differences. Fields, content types and values matched for duplicate names, file uploads, preamble and epilogue, lowercase headers, unquoted and UTF-8 names, and empty values.

Testing

Test 1: unit tests

Steps

  1. cargo test --lib try_parse_body

Result

9 tests pass. The 7 new tests cover a nested multipart body, a truncated body whose final field is still analyzed in part, unnamed fields being skipped, boundary transport padding, an invalid field Content-Type, a quoted name containing ;, and boundary text inside a value.

Test 2: attack detection through the WAF

Steps

  1. cargo test --test appsec_processor_test

Result

test_processor_detects_attack_in_multipart_field sends an API Gateway HTTP event with a <script> payload in the multipart field comment, using the default ruleset. The span gets appsec.event: true and a server.request.body match with key path ["comment"]. With the content type changed to text/plain, the test fails, because the WAF still matches but without the field key path.

Test 3: clippy

Steps

  1. cargo clippy --workspace --all-targets --features default, on main and on this branch.

Result

Same error count on both, so this change adds no new warnings. The errors come from the local rustc 1.99 toolchain.

Test 4: deployed function

Steps

  1. Deploy a Python 3.12 function behind a Lambda Function URL, with the Datadog Python layer, DD_SERVERLESS_APPSEC_ENABLED=true, AWS_LAMBDA_EXEC_WRAPPER=/opt/datadog_wrapper and DD_LOG_LEVEL=debug.
  2. Send three multipart/form-data requests, each with a <script> payload in the field comment:
    • A: a complete field.
    • B: a truncated final field (no closing boundary), after a complete field ok.
    • C: an unnamed field, then comment.
  3. Run once with the released extension layer and once with a layer built from this branch. Read the aap: lines in CloudWatch.

Result

Case Released layer (multipart) This branch (multer)
A: complete field 1 WAF event, body schema {comment} 1 WAF event, body schema {comment}
B: truncated final field 1 WAF event 1 WAF event, body schema {comment, ok}
C: unnamed field first 0 WAF events, body schema {} 1 WAF event
  • B on this branch logs failed to read multipart body entry comment: field "comment" received with incomplete data, and the truncated field still reaches the WAF.
  • C on the released layer logs expected additional data after Content-Disposition type: form-data and analyzes no fields. On this branch the unnamed field is skipped and comment is analyzed.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T16:53:38.964253Z b48ed8f Draft marked ready
🔒 Security Review ✅ Completed 2026-11-25T16:56:30.007878Z b48ed8f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

multipart 0.18 is unmaintained (RUSTSEC-2023-0050). Parse AppSec
multipart/form-data bodies with multer 3.1 instead and drop the
advisory ignore from deny.toml.

A truncated final field is still analyzed in part, as before. multer
discards its data, so it is taken from the raw body. Fields with an
invalid Content-Type, unnamed fields, quoted names containing ';',
boundary text inside a value, and transport padding are now handled
where multipart stopped or cut the data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@litianningdatadog

Copy link
Copy Markdown
Contributor Author

@codex review

@litianningdatadog
litianningdatadog marked this pull request as ready for review November 25, 2026 16:52
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b48ed8f | Docs | View more details | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant