Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for Byambadalai @ByamB4 for the report
Denial of Service via crafted form field
names.
Summary
formidable uses plain
{}objects to store parsed form fields.User-controlled field names overwrite inherited Object.prototype
methods (toString, valueOf, hasOwnProperty, constructor), potentially
causing unsafe downstream code to crash with TypeError.
Result
TypeError crashes on String() coercion and hasOwnProperty() calls.
Example
Impact
Any application using formidable where downstream code calls
hasOwnProperty(), String(), or uses string concatenation/template
literals on the parsed fields object will crash with TypeError.
Common vulnerable patterns in downstream code:
if (fields.hasOwnProperty("name")) {}- TypeErrorconst msg = "Data: " + fields- TypeErrorString(fields)or template literal interpolation - TypeErrorFix
fields and files now use Object.create(null) as a basis.
This means the error that could appear when receiving specifically crafted input, will now always appear instead.
This will hopefully force you to use safer code that does not use unsafe methods, on user input.
Upgrade Guide
If you already use a good linter, no further action is required.
Otherwise read below:
Find every occurence where fields and files are used in your code as a whole object. Adhere to the following:
Old and New
old:
if (fields.hasOwnProperty("name")) {}new:
if (Object.hasOwn(fields, "name")) {}old:
const msg = "Data: " + fieldsnew:
Convert to String individual fields instead, that are known and validated before
const msg = "Data: " + fields.a + fields.bold:
const msg = `Data: ${fields}`new:
Convert to String individual fields instead, that are known and validated before
const msg = `Data: ${fields.a} ${fields.b}` etc