Skip to content

Cap JSON Patch graft depth at the nesting limit (CVE-2026-67215) - #1115

Open
w4ffl35 wants to merge 1 commit into
DaveGamble:masterfrom
w4ffl35:fix/patch-amplification-depth
Open

w4ffl35 wants to merge 1 commit into
DaveGamble:masterfrom
w4ffl35:fix/patch-amplification-depth

Conversation

@w4ffl35

@w4ffl35 w4ffl35 commented Oct 26, 2026

Copy link
Copy Markdown

An untrusted RFC 6902 patch can graft duplicated subtrees via add/copy (or replace the root) to amplify the document past CJSON_NESTING_LIMIT -- e.g. one copy op taking a depth-602 document to depth 1202 -- setting up stack exhaustion in recursive passes.

This refuses grafts whose parent depth plus value depth would reach the limit (new status 12), including root replacement with an over-limit value. The depth helpers are self-bounding: value depth never recurses past the limit, and parent depth is counted from pointer separators (a raw '/' is always a separator since '/' in a key is escaped as ~1).

Evidence:

  • Reproducer: copy of a 600-deep subtree under a depth-600 parent now returns 12 with the document unchanged (was status 0, depth 1202); deep root replace refused; shallow copies unaffected. Full ctest suite passes (19/19).
  • Adds apply_patches_should_reject_grafts_past_the_nesting_limit and apply_patches_should_allow_grafts_within_the_nesting_limit to tests/misc_utils_tests.c.

Residual note: pure breadth amplification (many small grafts) is memory pressure, not stack exhaustion, and is intentionally out of scope here.

An untrusted RFC 6902 patch can graft duplicated subtrees via
add/copy (or replace the root) to amplify the document past
CJSON_NESTING_LIMIT, setting up stack exhaustion in recursive
passes. Refuse grafts whose parent depth plus value depth would reach
the limit (status 12), including root replacement with an over-limit
value. Depth helpers are self-bounding: value depth never recurses
past the limit, and parent depth is counted from pointer separators.

Add regression tests for rejection and the shallow success path.
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