Skip to content

fix: reject prototype keys in the worker's param tables - #6

Open
guillermolg00 wants to merge 1 commit into
Alain00:mainfrom
guillermolg00:fix/oneof-prototype-keys
Open

fix: reject prototype keys in the worker's param tables#6
guillermolg00 wants to merge 1 commit into
Alain00:mainfrom
guillermolg00:fix/oneof-prototype-keys

Conversation

@guillermolg00

Copy link
Copy Markdown

The one-line fix promised in the #4 thread, as its own PR so it does not wait on any design discussion.

oneOf validates with raw in table, and in walks the prototype chain — so /avatar/x?expression=__proto__ passes the roster, opts.expression becomes Object.prototype, and the render crashes when it calls e.vars(...). The catch only handles BadRequest, 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.hasOwn instead of in — same helper, so both tables are covered at once — keeping the original reason in was chosen (background=none maps to false, so a truthy lookup is still wrong). Regression cases added next to the roster test: __proto__, constructor, toString, and background=__proto__ all land on the usual 400.

Worker suite: 46 pass. Nothing else touched.

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.
Copilot AI lite review requested due to automatic review settings August 18, 2026 08:06
@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

@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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 table with Object.hasOwn(table, raw) in the shared oneOf helper to ensure only own keys are accepted.
  • Add regression tests covering prototype-chain keys for both expression and background parsing.

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`).
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.

2 participants