Skip to content

fix: set multipart flags on invalid C-D header, align tests - #3651

Open
airween wants to merge 3 commits into
owasp-modsecurity:v2/masterfrom
airween:v2/multipart-part-header-errors
Open

airween wants to merge 3 commits into
owasp-modsecurity:v2/masterfrom
airween:v2/multipart-part-header-errors

Conversation

@airween

@airween airween commented Oct 2, 2026

Copy link
Copy Markdown
Member

This PR was inspired by a bit wider, but similar for v3, #3650.

what

1. Parser flags for invalid part headers (apache2/msc_multipart.c)

  • MULTIPART_INVALID_PART (flag_invalid_part) is now set in multipart_process_part_header() when:
    • the part has no Content-Disposition header,
      -*the Content-Disposition header cannot be parsed (any negative result of multipart_parse_content_disposition()),
    • the name parameter is missing.
  • MULTIPART_INVALID_QUOTING (flag_invalid_quoting) is now also set when filename* has no valid charset before the first ' (error -16, e.g. a quoted filename*="UTF-8''...").

2. Regression tests check the parser state flags

  • tests/regression/target/10-variable-multipart_strict_error.t: seven cases now also match the logged flag values (error => [...]), the same as their v3 counterparts in variable-MULTIPART_STRICT_ERROR.json:
    • duplicate Content-Type part header: DH 1
    • filename* invalid syntax (-17): IQ 1
    • duplicate filename, duplicate filename*, duplicate filename after filename*: DH 1, IQ 0, IP 1
    • invalid percent-encoding in filename* (%ZZ, -18): DH 0, IQ 0, IP 1
    • quoted filename* (-16): DH 0, IQ 1, IP 1
  • tests/regression/misc/00-multipart-parser.t: the two "multipart mixed" cases log the flag values in the msg of the strict rule and check IP 1, as in v3.
  • The PARSER_STATE logdata and the new msg use RE %{REQBODY_ERROR} instead of PE %{REQBODY_PROCESSOR_ERROR}.

why

Flags. Unlike v3, the v2 parser already stops at the first invalid part header, because multipart_process_part_header() returns -1. However, these error paths only set the request body error. The individual flags stayed 0, so a rule or log line checking MULTIPART_INVALID_PART gave no hint that the part itself was invalid. With this change, v2 reports the same flag values as v3 for the same requests:

  • an invalid, missing or nameless Content-Disposition makes the part invalid,
  • a filename* without a valid charset is a quoting problem.

Tests. The existing cases only checked the debug log message, so the flag values were never verified. The five PARSER_STATE actions referenced REQBODY_PROCESSOR_ERROR. That variable was removed in 2.9.14 (#3578), so the macro expanded to an empty string (PE ,), and nothing caught it because no test looked at the output. REQBODY_ERROR is the variable v2's modsecurity.conf-recommended uses as well (RE %{REQBODY_ERROR}).

There is no behaviour change for request blocking: these requests were and still are rejected through REQBODY_ERROR. Only the values of MULTIPART_INVALID_PART and MULTIPART_INVALID_QUOTING change, and therefore MULTIPART_STRICT_ERROR, which already was 1 through the request body error.

references

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1c192ca8-ee20-405f-b1b0-f8d0292228db

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@airween
airween requested review from fzipi and a balanced review from Copilot October 2, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new missing-name flag path lacks a regression assertion for MULTIPART_INVALID_PART.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Aligns v2 multipart error flags and regression expectations with v3.

Changes:

  • Marks malformed, missing, or nameless Content-Disposition parts invalid.
  • Flags malformed filename* charset quoting.
  • Updates regression logging and assertions to use REQBODY_ERROR.
File Description
apache2/​msc_multipart.c Sets multipart invalid-part and invalid-quoting flags.
tests/​regression/​misc/​00-multipart-parser.t Verifies parser state for mixed multipart failures.
tests/​regression/​target/​10-variable-multipart_strict_error.t Updates state logging and flag expectations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apache2/msc_multipart.c
@airween
airween requested a balanced review from Copilot October 2, 2026 19:57
@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The parser changes are focused, consistent with existing flag semantics, and adequately covered by regression tests.

Review effort: Balanced
Findings: None

Resolved since last review (1)

This branch has not been deployed

No deployments
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.

3 participants