Skip to content

fix(provider): harden inbound request handling (security) - #2130

Merged
jonathan308 merged 6 commits into
devfrom
fix/inbound-json-depth-and-tool-schema-budget
Nov 14, 2026
Merged

jonathan308 merged 6 commits into
devfrom
fix/inbound-json-depth-and-tool-schema-budget

Conversation

@jonathan308

@jonathan308 jonathan308 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Hardens the provider's handling of inbound request bodies (security scan finding 325).

Details are withheld until the fix has reached the fleet. The full problem statement, tests and review are kept with the
release's private notes and will be published here after the rollout.

Testing

  • Red-first tests: the new tests fail on dev and pass on this head.
  • Independent review: approve.
  • CI: green.

jonathan308 and others added 4 commits November 13, 2026 15:20
…malization

A coordinator request's decrypted body is parsed by JSONSerialization and
JSONDecoder, which recurse once per object or array level, on a Swift
concurrency task whose stack is 512 KiB. A chat body of a few KB whose tool
schema nested a few hundred levels deep (128 in a debug build) exhausted that
stack and killed the provider with SIGBUS, below JSONSerialization's own
512-level limit. The coordinator forwards such bodies: it parses with Go's
decoder and normalizes tool schemas only to depth 64.

- Add `JSONNestingLimit`, a non-recursive scan that counts open containers
  and skips brackets inside strings. Refuse bodies deeper than 64 levels
  before any parse: in the coordinator handler right after decryption
  (`malformed_body`), in `repairedRequestBody` for every other caller, and in
  the local chat, batch, Responses and router paths (HTTP 400).
- Give tool-schema normalization a 100,000-node budget per request. Each
  positional `{}` or boolean became a two-key map, so a few MiB of them
  rewrote into ~85 MB of JSON and ~900 MiB of objects before decoding. Past
  the budget the body is decoded as sent, as one over 4 MiB already is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in the JSON limit

Refactor-pass follow-up to the JSON nesting limit.

- Refuse a body holding a NUL byte. Foundation's JSONSerialization and
  JSONDecoder also read UTF-16 and UTF-32 JSON, whose bytes the depth scan
  cannot count: a UTF-16 chat body with a 400-level tool schema passed the
  scan and still crashed the decoder (SIGBUS on dev). Every UTF-16 or UTF-32
  JSON text has a NUL byte; no UTF-8 one does.
- Check each tool call's `arguments` after decoding, on the coordinator path
  (refused as `invalid_tool_arguments`) and on the local chat, batch and
  Responses paths (400). The body scan skips JSON inside strings, and template
  rendering decodes and walks those arguments.
- Cover the SDK's other JSON routes on the local API (completions, tokenizer
  utilities, embeddings) with the same 2 MiB collection and check.
- Cleanups from the review: one refusal message constant, `refuses` naming,
  shared test builders, a router test, and the deepest accepted body decoding
  on a task's stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… NUL rule itself

Review follow-up. /apply-template renders its messages' tool calls, decoding each one's arguments, so its body is now decoded and its arguments checked like the chat path. The UTF-16/32 test now holds an escaped quote, so only the NUL rule (not the depth count) can refuse it, and it no longer decodes a body the scan let through. Router comments and the direct-mode doc match what is checked where.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference-landing Ready Ready Preview Nov 14, 2026 4:56am UTC
darkbloom-status Ready Ready Preview Nov 14, 2026 4:56am UTC
eigen-homepages-darkbloom Ready Ready Preview Nov 14, 2026 4:56am UTC

Request Review

…h-and-tool-schema-budget

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h-and-tool-schema-budget

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308 jonathan308 changed the title fix(provider): refuse deeply nested request JSON (provider crash) and bound schema normalization fix(provider): harden inbound request handling (security) Nov 14, 2026
jonathan308 added a commit that referenced this pull request Nov 14, 2026
- changelog.d/gemma-tool-grammar-linear-optional-members.md: generic public text (#2111)
- changelog.d/updater-signed-version-matches-release.md: generic public text (#2117)
- changelog.d/cluster-pairing-posture-is-self-reported.md: generic public text (#2129)
- changelog.d/inbound-json-depth-and-tool-schema-budget.md: generic public text (#2130)
- changelog.d/coordinator-inbound-queue-budget.md: generic public text (#2135)
- changelog.d/toml-parse-memory.md: generic public text (#2138)
- changelog.d/cluster-link-key-keychain.md: generic public text (#2137)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan308
jonathan308 merged commit b55122f into dev Nov 14, 2026
19 checks passed
jonathan308 added a commit that referenced this pull request Nov 18, 2026
The suite feeds seeded random and hostile model output, at every
chunking, through:

- the channel splitter;
- the tool frame;
- the SDK's ATEM reference reader and its strict parser;
- the scheduler's forwarding body, under every tool choice.

Each must hold up the way the inbound-depth (#2130), queue-budget
(#2135) and TOML (#2138) fixes were tested. It must not crash, stall,
buffer without bound, leak framing, raise invalidToolPayload or return
a 500. A frame the model gets wrong is the model's error, a 422.

deepNesting and the deep hostile frames need the nesting bounds of
mlx-swift-lm #423 (824db4cf and 31a7ccb2, from d266d4e6 and 7f958c64)
in the pin; this branch pins b7672434, which has them. Without them, a value
nested a few hundred levels deep stops the test process with SIGBUS,
as it would stop a provider.

repeatedStrayCloses took about two minutes in a debug build while the
splitter rescanned the tool body on every stray closing tag; with the
linear splitter of #2149 (e2c60ca) it takes about a second.

Test-only.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch was successfully deployed

3 active deployments
Preview – d-inference-landing — 3f0a2432 Deployed Nov 14, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 3f0a2432 Deployed Nov 14, 2026 by vercel[bot]
Preview – darkbloom-status — 3f0a2432 Deployed Nov 14, 2026 by vercel[bot]
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