Skip to content

fix: prevent multipart part header injection - #29

Merged
fengmk2 merged 1 commit into
masterfrom
codex/fix-multipart-header-injection
Nov 14, 2026
Merged

fengmk2 merged 1 commit into
masterfrom
codex/fix-multipart-header-injection

Conversation

@fengmk2

@fengmk2 fengmk2 commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Untrusted field names, filenames, and MIME types can inject multipart headers and change the field name seen by a receiving parser.

The fix encodes CR, LF, and double quotes in field names and filenames as %0D, %0A, and %22. MIME types with CR or LF cause a synchronous TypeError before the form attaches or pipes a source stream. Other characters and part contents remain unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Multipart field names and filenames now safely encode carriage returns, line feeds, and double quotes, preventing them from altering headers.
    • MIME types containing carriage returns or line feeds are rejected with a TypeError. The form remains usable after rejection.
    • Ordinary metadata and field contents are unchanged.
  • Documentation
    • Clarified multipart encoding behavior and documented the optional mimeType argument for field().

@agentscanapp

agentscanapp Bot commented Nov 14, 2026

Copy link
Copy Markdown

Mixed activity

Activity patterns show a mix of organic and automated signals.

View full analysis →

Evidence
  • Posts through an AI agent: Codex posted 2 of the account's 12 comments and issues (17%)

This is an automated analysis by AgentScan

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Multipart disposition values now encode carriage returns, line feeds, and double quotes. MIME types containing carriage returns or line feeds are rejected synchronously. Documentation and tests cover these behaviors.

Changes: Multipart header handling

Layer / File(s) Summary
Encode disposition values and validate MIME types
lib/formstream.js, README.md
Disposition values are stringified and percent-encoded for CR, LF, and quotes. MIME types containing CR or LF now throw a TypeError. The stream() method constructs the part header before registering source stream handlers. The README documents the encoding, validation, and optional field() MIME type.
Verify multipart header behavior
test/header-injection.test.js, test/formstream.test.js
Tests cover encoded field names and filenames, MIME type rejection, unchanged metadata and field contents, content length, and form reuse after rejection.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: xingrz

Merge Risk: Minimal · up to e2dfb

This change prevents multipart header injection from untrusted field names, filenames and MIME types, and leaves other characters and part contents unchanged. The supplied tests and documentation cover the new behavior, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: prevent multipart part header injection" matches the main change. The summary shows percent-encoding of CR, LF, and double quotes in field names and filenames, plus TypeError rejection…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: prevent multipart part header injection" matches the main change. The summary shows percent-encoding of CR, LF, and double quotes in field names and filenames, plus TypeError rejection of MIME types containing CR or LF. The title is specific, concise, and uses the conventional fix: prefix.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c9cbe4b8-cf4e-4781-b004-4245059c5f3e
Commits

Reviewing files that changed from the base of the PR and between f6096dc and e2dfb12.

Files selected for processing: 4

  • README.md
  • lib/formstream.js
  • test/formstream.test.js
  • test/header-injection.test.js

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.24%. Comparing base (ace05e0) to head (e2dfb12).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #29      +/-   ##
==========================================
+ Coverage   98.21%   98.24%   +0.02%     
==========================================
  Files           1        1              
  Lines         393      399       +6     
  Branches       58       64       +6     
==========================================
+ Hits          386      392       +6     
  Misses          7        7              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2
fengmk2 merged commit d707e15 into master Nov 14, 2026
42 of 48 checks passed
@fengmk2
fengmk2 deleted the codex/fix-multipart-header-injection branch November 14, 2026 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant