fix: guard #set paths against prototype pollution#188
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b9a030d02a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c7e6f0d05
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 221d197e1b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Background
Supersedes #186, which has been closed. The previous approach blocked dangerous key names too broadly and still needed more careful handling for dynamic index paths.
Prototype pollution is possible when
#settraverses through JavaScript prototype accessors such as__proto__or inheritedconstructor.prototypebefore assigning the final property.Approach
Resolve the left-hand
#settarget before evaluating the right-hand value. If the path would traverse a prototype-polluting segment, skip the assignment before any RHS side effects run.The guard is path-aware rather than a blanket key denylist:
__proto__paths.constructor/prototypetraversal and functionprototypetraversal.$constructor/$prototypeassignments.constructor/prototypedata fields on ordinary context objects.For dynamic index keys, the key is now resolved before the RHS value. This is intentional so blocked dynamic paths do not execute RHS callbacks.
Changes
src/compile/set.tsto resolve and validate#setpaths before assignment.__proto__, inheritedconstructor.prototype, dynamic index keys, and function prototype paths.constructor/prototypevariables and own data fields with those names.Testing
./node_modules/.bin/jest --config=jest.config.js test/set.test.ts --runInBandnpm run lintnpm test -- --runInBandnpm run test:buildLocal Review