Skip to content

fix(catalog): prevent prototype pollution in path utilities - #816

Open
jong-k wants to merge 1 commit into
cloudflare:mainfrom
jong-k:fix/setbypath-prototype-pollution
Open

jong-k wants to merge 1 commit into
cloudflare:mainfrom
jong-k:fix/setbypath-prototype-pollution

Conversation

@jong-k

@jong-k jong-k commented Sep 21, 2026

Copy link
Copy Markdown

Summary

setByPath and getByPath in @cloudflare/kumo/catalog walk untrusted, AI-generated JSON Pointer paths against the data model. Both traversed the prototype chain, so a path like /__proto__/polluted or /constructor/prototype/polluted could write to Object.prototype, and /constructor or /toString could read prototype members into resolved props / visibility checks.

  • Reject __proto__, constructor, and prototype segments in both getByPath and setByPath (defense-in-depth).
  • Use Object.hasOwn instead of in / bare indexing so only own properties are traversed.
  • Treat null intermediates the same as missing (previously typeof null === "object" let traversal fall through and throw).
  • Skip writes to an array's length (previously RangeError: Invalid array length on /items/length/x).
  • Return early for empty / root paths in setByPath, mirroring getByPath.
  • Add regression tests and a patch changeset.

No behavior change for plain JSON data models (DataModel = Record<string, unknown>); array index access (/items/0) still works.

Testing

  • pnpm --filter @cloudflare/kumo test: 59 files, 1403 passed
  • pnpm --filter @cloudflare/kumo lint
  • pnpm --filter @cloudflare/kumo typecheck
  • pnpm vp fmt --check on changed files
  • git diff --check

  • Reviews
    • bonk has reviewed the change
    • automated review not possible because: external contributor, no access to bonk
  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:

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.

1 participant