[12.x] Guard JsonSchema deserializer against unbounded $ref expansion#60524
Merged
taylorotwell merged 1 commit intoJun 16, 2026
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #60517 to 12.x.
When deserializing a schema whose
$defsreference each other,fromArray()inlines each$refinto the type tree. With a lot of nested cross-references this expansion can grow very large and use a surprising amount of time and memory before you get anything back.This adds a cap on how many fragments a single schema can expand into, throwing
InvalidArgumentExceptiononce it goes past the limit instead of churning. Normal schemas are nowhere near it, so valid input is unaffected. Also includes two small behavior-preserving tweaks in the same method (array_fliplookup forrequired, and memoizinglookupRef).Repro
A small schema where each
$defsentry references the next one twice expands exponentially with depth:With this change the same input throws
InvalidArgumentExceptiononce it crosses the limit instead of consuming large amounts of memory and time.