fix: reject prototype keys in the worker's param tables - #6
Open
guillermolg00 wants to merge 1 commit into
Open
Conversation
oneOf validated with `in`, which walks the prototype chain: __proto__ and constructor passed the roster and came back as Object.prototype, crashing the render — a caller typo served as a 500. Own-property check plus regression cases in the suite.
|
@guillermolg00 is attempting to deploy a commit to the alain00's projects Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the site Worker’s query-param validation by ensuring allowlist lookups don’t traverse the prototype chain, preventing inherited keys like __proto__/constructor from being accepted and causing downstream rendering crashes.
Changes:
- Replace
raw in tablewithObject.hasOwn(table, raw)in the sharedoneOfhelper to ensure only own keys are accepted. - Add regression tests covering prototype-chain keys for both
expressionandbackgroundparsing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/site/worker/params.ts | Switches oneOf to an own-property check to prevent prototype-chain key acceptance. |
| apps/site/worker/params.test.ts | Adds regression tests to ensure prototype keys are rejected with BadRequest. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+84
to
+88
| // An own-property check rather than `in` or a truthy lookup. `in` walks the | ||
| // prototype chain, so "__proto__" and "constructor" passed and handed back | ||
| // Object.prototype — not a value of the table, and a crash downstream. A | ||
| // truthiness check would reject the one value that has to be falsy | ||
| // (`background=none` maps to `false`). |
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.
The one-line fix promised in the #4 thread, as its own PR so it does not wait on any design discussion.
oneOfvalidates withraw in table, andinwalks the prototype chain — so/avatar/x?expression=__proto__passes the roster,opts.expressionbecomesObject.prototype, and the render crashes when it callse.vars(...). Thecatchonly handlesBadRequest, so a caller typo is served as a 500 today.background=__proto__slips through the same way (milder: it renders the default backdrop).Fix:
Object.hasOwninstead ofin— same helper, so both tables are covered at once — keeping the original reasoninwas chosen (background=nonemaps tofalse, so a truthy lookup is still wrong). Regression cases added next to the roster test:__proto__,constructor,toString, andbackground=__proto__all land on the usual 400.Worker suite: 46 pass. Nothing else touched.