Skip to content

fix lack of escaping of filename in Content-Disposition#545

Draft
motoyasu-saburi wants to merge 4 commits intoform-data:masterfrom
motoyasu-saburi:fix-request-tampeing-vuln
Draft

fix lack of escaping of filename in Content-Disposition#545
motoyasu-saburi wants to merge 4 commits intoform-data:masterfrom
motoyasu-saburi:fix-request-tampeing-vuln

Conversation

@motoyasu-saburi
Copy link

@motoyasu-saburi motoyasu-saburi commented Apr 1, 2023

Fixes #546

@ljharb ljharb marked this pull request as draft September 19, 2024 23:22
@motoyasu-saburi motoyasu-saburi marked this pull request as ready for review November 23, 2024 02:39
motoyasu-saburi and others added 3 commits November 23, 2024 11:41
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
@motoyasu-saburi
Copy link
Author

I'm Sorry for the delay in getting back to you.

I'm having problems with CI in Automatic Rebase.
If @ljharb could please advise me, I would appreciate it.

@ljharb
Copy link
Member

ljharb commented Nov 23, 2024

Don't worry about that check; that's failing because you merged the upstream changes instead of rebased them. I can rebase the PR later.

contentDisposition = 'filename="' + filename + '"';
// Escaping to prevent CRLF Injection / tampering with invalid fields.
// https://html.spec.whatwg.org/#multipart-form-data
var escapedFilename = filename.replaceAll('"', '%22')
Copy link
Member

Choose a reason for hiding this comment

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

unfortunately replaceAll isn't available in all engines we support. what about this?

Suggested change
var escapedFilename = filename.replaceAll('"', '%22')
var escapedFilename = filename.replace(/"/g, '%22')

body += chunk;
});
req.on('end', function () {
assert(body.includes(escapedContentDispositionHeader), 'Expects encode "filename" field');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assert(body.includes(escapedContentDispositionHeader), 'Expects encode "filename" field');
assert(body.indexOf(escapedContentDispositionHeader) >= 0, 'Expects encode "filename" field');

similarly, includes isn't available in everything either.

@ljharb ljharb marked this pull request as draft November 23, 2024 06:33
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.

"form-data" is vulnerable to request tampering via a crafted filename

2 participants