Repository navigation
security: cap cloneNode/isEqualNode recursion depth - #275
Merged
Merged
Conversation
Continuing the same sweep as the calc()/:not()/:is() CSS parser fixes, this time across JS-reachable DOM methods: isEqualNode (node.isEqualNode(other)) and cloneNode (node.cloneNode(deep), also document.importNode) each recurse over a node's own Children with no depth check -- and unlike round 166's cascade/layout caps, nothing here guards a script calling one of these directly on a tree it already has, independently of whether that tree is ever rendered. Confirmed with a 10,000-deep synthetic chain (dom.AppendChild has no depth check of its own, by design) that both recurse unboundedly. Fixed with a depth parameter capped at maxDOMWalkDepth = 512, matching the HTML parser's own bound. Past the cap, isEqualNode reports false (never crashing) and cloneNode stops descending, returning a real node with an empty subtree rather than failing the whole call. Co-Authored-By: Claude Sonnet 5 <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.
Summary
Continuing the same sweep as the calc()/:not()/:is() CSS parser fixes (#273/#274), this time across JS-reachable DOM methods:
isEqualNode(node.isEqualNode(other)) andcloneNode(node.cloneNode(deep), alsodocument.importNode) each recurse over a node's ownChildrenwith no depth check — and unlike round 166's cascade/layout caps, nothing here guards a script calling one of these directly on a tree it already has, independently of whether that tree is ever rendered.Confirmed with a 10,000-deep synthetic chain (
dom.AppendChildhas no depth check of its own, by design) that both recurse unboundedly. Fixed with a depth parameter capped atmaxDOMWalkDepth = 512, matching the HTML parser's own bound. Past the cap,isEqualNodereportsfalse(never crashing) andcloneNodestops descending, returning a real node with an empty subtree rather than failing the whole call.Test plan
go build ./...go test ./...(all packages pass)js/dom_test.go:TestIsEqualNodeDoesNotCrashOnPathologicallyDeepTree,TestIsEqualNodeDeepMismatchPastCapIsNotEqual,TestCloneNodeDoesNotCrashOnPathologicallyDeepTreejspackage coverage unaffected (95.9% baseline)🤖 Generated with Claude Code