html/template: handle CDATA in foreign script elements#80492
Open
carrerasdarren-cell wants to merge 1 commit into
Open
html/template: handle CDATA in foreign script elements#80492carrerasdarren-cell wants to merge 1 commit into
carrerasdarren-cell wants to merge 1 commit into
Conversation
HTML tokenizers treat CDATA sections in SVG and MathML as text. html/template currently recognizes an apparent </script> within such a section as the end of a script element and applies HTML instead of JavaScript escaping to later actions. In a template literal, this can allow attacker-controlled interpolation and XSS. Track foreign-content namespaces and HTML integration points, and preserve JavaScript context through CDATA sections in foreign script elements. Fixes golang#62617.
Contributor
|
This PR (HEAD: ab384bd) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/803621. Important tips:
|
Contributor
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/803621. |
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.
HTML tokenizers recognize CDATA sections when the current node is SVG or
MathML. An apparent closing script tag inside such a section is text, but
html/template currently ends its script context there. A later action is
therefore HTML-escaped instead of JavaScript-escaped. In a template literal,
attacker-controlled interpolation can execute.
This change tracks the foreign namespace transitions that affect CDATA,
including HTML integration points and breakout tags, and preserves the
JavaScript context until the CDATA section ends. Dynamically ambiguous
attributes retain the stricter JavaScript-escaping direction.
The issue reproducer was confirmed on current master. With an inert local
payload that assigned 1337 to a sentinel, headless Chrome changed the sentinel
from 0 to 1337. The patched rendering escaped the interpolation syntax and the
sentinel remained 0.
Validation included the complete short standard-library suite, ten
race-enabled html/template runs, 100 ordinary html/template runs, and go vet.
Fixes #62617.