Skip to content

fix(server): reject over-deep JSON request bodies before parsing - #747

Merged
seonghobae merged 2 commits into
mainfrom
fix/json-body-nesting-depth-guard-strix-20260818
Aug 19, 2026
Merged

fix(server): reject over-deep JSON request bodies before parsing#747
seonghobae merged 2 commits into
mainfrom
fix/json-body-nesting-depth-guard-strix-20260818

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

Summary

  • Strix (running on PR fix(api): casefold message roles and tool/function types over HTTP #716's changed-file scope) reported a MEDIUM finding: _coerce_json parses request bodies with json.loads with no nesting-depth cap, so a deeply nested payload well under max_body_bytes can still burn disproportionate CPU/stack during parsing (JSON bomb DoS).
  • Add _reject_excessive_json_nesting: a cheap, stdlib-only byte scan (skips over string contents correctly) that rejects nesting past MAX_JSON_NESTING_DEPTH (32) before json.loads ever runs.
  • fuzz/targets.py::exercise_request_body already treated RecursionError as an expected/benign outcome of deep nesting; this fix removes that failure mode entirely by rejecting it earlier with a proper RequestError.

Test plan

  • python tests/test_request_body_json_depth.py
  • python -m pytest tests/test_request_body_json_depth.py -q
  • python -m pytest tests/fuzz -q
  • python -m pytest tests -q --ignore=tests/fuzz (296 passed)
  • CI product gates (Full unit + Semgrep, Strix re-scan)

Strix found that _coerce_json had no nesting-depth cap: a payload well
under max_body_bytes but deeply nested (JSON bomb) burns disproportionate
CPU during json.loads. Reject nesting past MAX_JSON_NESTING_DEPTH with a
cheap byte scan before parsing, closing the DoS path the fuzz target's
RecursionError handling only papered over.

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

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 3 minutes

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits within each organization.

For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 97ce65be-0d66-411c-a7a6-000704bfb3f6

📥 Commits

Reviewing files that changed from the base of the PR and between be40de0 and a842c4d.

📒 Files selected for processing (2)
  • contextual_orchestrator/server.py
  • tests/test_request_body_json_depth.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head f2b993bfddbfd5cb82bf251065709dba596f90a6.

  • Head SHA: f2b993bfddbfd5cb82bf251065709dba596f90a6

  • Workflow run: 32189622069

  • Workflow attempt: 1

Coverage evidence

Coverage evidence job did not run or did not publish coverage evidence.

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file: server.py"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file: server.py"]
  R1 --> V1["required checks"]
  Evidence --> S2["Test: test_request_body_json_depth.py"]
  S2 --> I2["regression suite"]
  I2 --> R2["Review risk: Test: test_request_body_json_depth.py"]
  R2 --> V2["targeted test run"]
Loading

@opencode-agent

opencode-agent Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

OpenCode Review Overview

  • Head SHA: f2b993bfddbfd5cb82bf251065709dba596f90a6
  • Workflow run: 32194255112
  • Workflow attempt: 1
  • Gate result: REQUEST_CHANGES (approval step)

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head f2b993bfddbfd5cb82bf251065709dba596f90a6.

  • Head SHA: f2b993bfddbfd5cb82bf251065709dba596f90a6

  • Workflow run: 32194255112

  • Workflow attempt: 1

Coverage evidence

Coverage evidence job did not run or did not publish coverage evidence.

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file: server.py"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file: server.py"]
  R1 --> V1["required checks"]
  Evidence --> S2["Test: test_request_body_json_depth.py"]
  S2 --> I2["regression suite"]
  I2 --> R2["Review risk: Test: test_request_body_json_depth.py"]
  R2 --> V2["targeted test run"]
Loading

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

OpenCode cannot approve yet because required coverage evidence did not pass.

Review outcome

1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence

  • Problem: The required coverage-evidence job result was failure, so OpenCode cannot establish approval sufficiency for this head.

  • Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.

  • Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports success with required evidence or explicit no-source not-applicable evidence.

  • Regression test: Keep the approval branch checking needs.coverage-evidence.result == success before posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present.

  • Result: REQUEST_CHANGES

  • Reason: coverage-evidence result was failure, so required test/docstring evidence was not proven for current head f2b993bfddbfd5cb82bf251065709dba596f90a6.

  • Head SHA: f2b993bfddbfd5cb82bf251065709dba596f90a6

  • Workflow run: 32194255112

  • Workflow attempt: 1

Coverage evidence

Coverage evidence job did not run or did not publish coverage evidence.

Changed-File Evidence Map

flowchart LR
  PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
  Evidence --> S1["Changed file: server.py"]
  S1 --> I1["repository behavior"]
  I1 --> R1["Review risk: Changed file: server.py"]
  R1 --> V1["required checks"]
  Evidence --> S2["Test: test_request_body_json_depth.py"]
  S2 --> I2["regression suite"]
  I2 --> R2["Review risk: Test: test_request_body_json_depth.py"]
  R2 --> V2["targeted test run"]
Loading

@seonghobae
seonghobae dismissed stale reviews from opencode-agent[bot] and opencode-agent[bot] August 19, 2026 01:24

Dismissing: mechanical 'coverage-evidence result was failure' rejection (root cause: atheris==3.0.0 has no Python 3.14 wheel, breaking the central coverage-sandbox build for every PR org-wide regardless of diff; real fix in #752, merging shortly). Not a content objection to this PR.

@seonghobae
seonghobae merged commit 97aa4e6 into main Aug 19, 2026
32 checks passed
@seonghobae
seonghobae deleted the fix/json-body-nesting-depth-guard-strix-20260818 branch August 19, 2026 01:24
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