Skip to content

fix(security): harden tool argument sanitization against special keys - #313

Open
mcollina wants to merge 1 commit into
mainfrom
fix-sanitize-tool-params-special-keys
Open

mcollina wants to merge 1 commit into
mainfrom
fix-sanitize-tool-params-special-keys

Conversation

@mcollina

@mcollina mcollina commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Harden sanitizeToolParams() against special property names and key collisions.

The sanitizer copied entries with direct assignment, so an already-parsed object carrying a __proto__ key could invoke the inherited setter and change the prototype of the sanitized result. It now copies each property with Object.defineProperty as a plain own data property, so __proto__, constructor and prototype are handled safely as ordinary keys at every nesting level (including inside arrays).

When stripping control characters maps two different input keys onto the same output key, the sanitizer now throws a Duplicate key error instead of silently dropping one of the values.

Added direct and nested regression coverage for special property names, keys that sanitize into a special name, and key collisions, plus an end-to-end check that a colliding tool call is refused before the handler runs. Documented both safeguards in the README.

Fixes #311

Copy sanitized object properties with defineProperty instead of direct
assignment. Assignment on an ordinary object invokes inherited accessors
for special names such as __proto__, letting untrusted input change the
prototype of the sanitized result. defineProperty always creates a plain
own data property, so __proto__, constructor and prototype are handled
safely as ordinary keys.

Throw a Duplicate key error when stripping control characters maps two
different input keys onto the same output key, instead of silently
dropping one of the values.

Add direct and nested regression coverage (including objects inside
arrays) for special property names, a key that sanitizes into a special
name, and key collisions.

This branch has not been deployed

No deployments
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.

Harden tool argument sanitization against special property names

1 participant