Skip to content

fix: escape multipart filenames to prevent header injection - #984

Open
fengmk2 wants to merge 4 commits into
masterfrom
codex/fix-multipart-filename
Open

fengmk2 wants to merge 4 commits into
masterfrom
codex/fix-multipart-filename

Conversation

@fengmk2

@fengmk2 fengmk2 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Multipart uploads insert filenames into Content-Disposition without escaping CR, LF, or double quotes. These characters can inject additional part headers.

Encode CR, LF, and double quotes as %0D, %0A, and %22. Require form-data@^4.0.6 for safe field names and formstream@^1.5.3 for safe metadata in legacy stream bodies. MIME types containing CR or LF cause a synchronous TypeError in formstream.

Preserve the existing filename* behavior for non-ASCII filenames. Allow formstream@1.5.3 through the minimum release age check so the security fix can be installed immediately.

Summary by CodeRabbit

  • Bug Fixes
    • Multipart form filenames and field names now safely escape quotes and line breaks, preventing them from altering headers or creating unintended form parts.
    • Non-ASCII filenames and custom file paths continue to be represented in multipart data.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 05:10
@agentscanapp

agentscanapp Bot commented Nov 17, 2026

Copy link
Copy Markdown

Automation signals

Activity patterns show signs of automation.

View full analysis →

Report this account →

Evidence
  • PRs to many projects in one day: Opened PRs in 70 different repos within 24 hours
  • Very high PR volume (daily): 71 PRs within a single 24-hour window, 39 of them to repos it can push to
  • High PR volume (weekly): 71 PRs within a single 7-day window, 39 of them to repos it can push to

Last 5 PRs:

This is an automated analysis by AgentScan

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Multipart filename serialization now escapes carriage returns, line feeds, and double quotes. Tests cover filename and field-name escaping, and the form-data and formstream dependency ranges are updated.

Changes: Multipart header handling

Layer / File(s) Summary
Escape multipart header values
src/FormData.ts, test/formData.test.ts, test/options.files.test.ts, package.json, pnpm-workspace.yaml
_getContentDisposition escapes CR, LF, and double quotes in quoted filenames. Tests cover serialized multipart bodies, custom filepaths, file sources, parsed file data, and field names. The dependency ranges are updated, and formstream@1.5.3 is added to minimumReleaseAgeExclude.

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

Change: Bug fix

Merge Risk: Minimal · up to 1ed15

This change escapes carriage returns, line feeds, and double quotes in multipart filenames, which prevents header injection, and it raises the form-data and formstream dependency minimums. No merge-blocking risk was identified.

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: escape multipart filenames to prevent header injection" matches the main change. The FormData._getContentDisposition method now percent-escapes CR, LF, and double quotes in the filenam…
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: escape multipart filenames to prevent header injection" matches the main change. The FormData._getContentDisposition method now percent-escapes CR, LF, and double quotes in the filename parameter, and tests verify that hostile filenames no longer inject headers or extra parts. The title is concise, specific, and does not use vague terms. The package bumps and the formstream release-age exclusion are secondary and do not need to appear in the title.

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: 74c591b7-3bfa-403a-9fe4-221b609d07e6
Commits

Reviewing files that changed from the base of the PR and between 99741f8 and 1ed1535.

Files ignored due to path filters: 1

  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing: 5

  • package.json
  • pnpm-workspace.yaml
  • src/FormData.ts
  • test/formData.test.ts
  • test/options.files.test.ts

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

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedformstream@​1.5.2 ⏵ 1.5.3100 +1100100 +188 +7100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/node-modules/urllib@984

commit: 1ed1535

@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.91%. Comparing base (99741f8) to head (1ed1535).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #984      +/-   ##
==========================================
+ Coverage   94.77%   94.91%   +0.14%     
==========================================
  Files          10       10              
  Lines         746      747       +1     
  Branches      235      235              
==========================================
+ Hits          707      709       +2     
+ Misses         36       35       -1     
  Partials        3        3              

☔ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the multipart upload hardening changes.

No open issues 🎉

1 file not reviewed
  • pnpm-lock.yaml: Generated file
What changed in this PR

This PR hardens urllib’s multipart uploads against header injection by escaping unsafe filename characters and requiring patched multipart dependencies.

Changes:

  • Escape CR, LF, and double quotes in filenames while preserving existing non-ASCII filename* behavior.
  • Add regression tests for filename and field-name escaping across upload sources.
  • Raise dependency minimums and exempt formstream@1.5.3 from the minimum release age check.
File Description
test/​options.files.test.ts Tests injection prevention across upload sources and normal field names.
test/​formData.test.ts Tests filename escaping, compatibility, and normalized filepaths.
src/​FormData.ts Escapes unsafe filename characters before header serialization.
pnpm-workspace.yaml Allows immediate installation of formstream@1.5.3.
pnpm-lock.yaml Updates dependency requirements and locks the patched formstream release.
package.json Requires form-data@^4.0.6 and formstream@^1.5.3.

Review effort: Balanced

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants