fix: prevent prototype pollution via __proto__ in FormData field names#4
Merged
Conversation
added 4 commits
May 8, 2026 22:00
`parseFormData` walked bracket and dot-notation field names into nested objects without filtering reserved property keys. A single field whose name began with `__proto__` (or contained `.__proto__.` mid-path) caused the parser to traverse and assign onto `Object.prototype`, polluting the prototype chain of every plain object in the running process. `handlePathPart` now throws a new `ForbiddenKeyError` (also exported) when an object-type path segment is `__proto__`, `constructor`, or `prototype`. The array branch is unaffected today - the regex restricts array-index segments to digits only - and three new tests pin that invariant so a future regex change would surface the gap. Reported responsibly by Mohamed Bassia (https://github.com/0xBassia).
The shipped artifact () uses nullish coalescing (), which requires Node 14+. Node 12 has been unable to import the published package since 1.0.0; the matrix entry was misleading rather than load-bearing. The CI lint step also fails on Node 12 because (transitively required via ) uses the import scheme, which was added in Node 14.18 and is unsupported on Node 12. Node 12 has been EOL since April 2022.
|
🎉 This PR is included in version 1.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Summary
parseFormDatawalked bracket- and dot-notation field names into nestedobjects without filtering reserved property keys. A single FormData field
whose name began with
__proto__, or contained.__proto__.mid-path,caused the parser to traverse and assign onto
Object.prototype,polluting the prototype chain of every plain object in the running
process.
Fix
handlePathPartnow throws a newForbiddenKeyError(also exported)when any path segment is
__proto__,constructor, orprototype.The check runs before object/array type branching, so it covers both
a.__proto__.xand any future code path that might route a forbiddenkey through the array branch.
The array branch was not exploitable in practice today - the regex
restricts array-index segments to digit characters - but applying the
check uniformly removes the dependence on that invariant. Three new
tests assert that
a[__proto__],a[constructor], anda[prototype]throw and never pollute, so any future regex change that loosens the
input shape will surface the gap loudly rather than silently.
Tests
src/__tests__/index.tsRelease impact
Conventional
fix:commit → semantic-release will cut 1.0.1(patch). Previously-accepted inputs with
__proto__/constructor/prototypesegments now throwForbiddenKeyError- no legitimate useof these as form field names is expected to be affected.
Disclosure
Reported responsibly by Mohamed Bassia
(@0xBassia) via private email. A GitHub
Security Advisory with CVE assignment will be published after 1.0.1
lands on npm so that downstream users are notified through Dependabot
and
npm audit.This PR also adds
SECURITY.mddocumenting the disclosure channel forfuture reports.