Repository navigation
Track the output context under the name the renderer writes - #541
Merged
Merged
Conversation
HtmlStreamRenderer writes xmp, listing and plaintext as pre. A browser ends SVG and MathML content at pre but not at xmp or plaintext, so the policy's output tracker, fed the policy's name, stayed in foreign content after <svg><xmp> while the browser had left it. An image start that followed was then kept as SVG and built by the browser as an HTML img, bypassing the image check from #534 in policies that allow svg, image and xmp but not img. When the output is the library's renderer, the policy now judges each kept element under the name the renderer will write. Other receivers still get, and are tracked under, the policy's name. Reported by Irhas Abdul Rosyid (@analisaperlengkapan). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nderer Sol's review found that a postprocessor passing every event on unchanged hides the renderer from the policy, which then tracked xmp under its own name and kept the image after <svg><xmp> again. A receiver the library cannot see through still gets the policy's name, since #474 relies on it, but where that name and the renderer's would put a start tag in different namespaces the output context now becomes unknown, so later image elements are dropped as after a retained template. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From Fable's review: the change-log bullet now names math, plaintext and element-policy names and says the exact tracking holds for the library's renderer; the outIsLibraryRenderer javadoc says it now also decides the tracked name; the regression test also runs a void element renamed to xmp, a wrapper-subclass postprocessor and a change listener. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the Opus review. After a retained template the output context is unknown, and an unknown context judges a template start as HTML, so the template's own context started known. Inside math a browser makes that template a MathML one: an svg in it is MathML and its mtext a text integration point, where image builds img. The sanitizer took the image for SVG and kept it, under any sink, as <template></template><math><template><svg><mtext><image src=...>. It also reopened the fail-closed path of the previous commit for receivers that forward to the renderer. Such a template's content now starts unknown. The cost is that SVG images in a template that follows another template are dropped. The change-log wording on receivers is also corrected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From Fable's final-head review: the template-context field and push comment now say a context can start unknown and that the image must sit in a text integration point; a long run of templates and renamed raw text under a forwarding receiver runs in linear time at -Xmx256m. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fable's final-head review found three ways, all already on main, for an image the sanitizer kept as SVG to be built as an HTML img: - An element kept inside a same-named HTML element whose content a browser reads as text: <noscript><svg><noscript></noscript><image> (scripting on), and title, textarea, noembed and noframes given children by an element policy or an event caller. The inner end tag ends the outer element early. An element of such a name, in any case, is now dropped while one is open as HTML in the output, counted per name so the check is constant time. - The first table part in a template's content switches a browser to a table mode, where math and svg are ignored or placed elsewhere. A template context now becomes unknown at such a tag. testForeignEndTagDoesNotReachOlderHtmlAncestor pinned an svg noscript inside an HTML noscript as expected output, which is the first shape; its expectations now drop the inner element and say why, and its browser comparison checks that the trees differ by that element alone. AGENTS.md lists the class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the Opus review of a150c46: noembed and noframes are text to a browser whatever the scripting state; a table part switches a template only before any other start tag; the mode is table body, not body; the template test names the shapes Chrome builds as img and says the rest pin the fail-closed rule; the hostile-size run includes a template table part. Co-Authored-By: Claude Opus 5.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.
HtmlStreamRendererwritesxmp,listingandplaintextaspre. A browser ends SVG and MathML content atpre, but not atxmporplaintext. The policy's output foreign-content tracker was fed the policy's name, not the name the renderer writes. So after<svg><xmp>it still treated the output as SVG, and theimagecheck from #534 kept a following<image>, which the browser builds as an HTMLimg.Policy allows
svg,image(withsrc) andxmp, but notimg:<svg><pre></pre><image src="https://attacker.example/xss.js"></image></svg>svg pre img, URL fetched<svg></svg><pre></pre>svg pre, no requestFix
When the output is the library's renderer,
applyPoliciesnow gives each kept element the name the renderer will write (HtmlStreamRenderer.safeName). The output tracker, the output stack, and the tag balancer's queries to the policy then all seepre, as they already did for a literal<pre>. The rendered text is unchanged apart from where the foreign root closes. Other receivers still get, and are tracked under, the policy's name.Tests
testRenamedRawTextElementEndsForeignContent: covers the report's variants (<xmp/>,<XMP>, insidemath,g,mianddesc, pluslistingandplaintext), names introduced by element policies, and direct events. Each keptimagemust parse as SVG or MathML, and noimgmay appear in the parsed tree. Fails on main.testForeignImageAroundRenamedRawTextElementIsKept: an SVGimagebefore the breakout, or inside a new root after it, is still kept. Fails on main because the output shape changed.testCustomReceiverStillGetsThePolicyName: pins the custom-receiver behaviour.testTemplateUnderUnknownContextIsNotKnownForeignContent: covers every MathML text and HTML integration point, under plain and forwarding sinks. Fails on main.testTextContentElementIsNotNestedInItselfandtestTableModeInTemplateIsNotKnownForeignContentboth fail on main../mvnw clean verifypasses on JDK 11, 17, 21 and 25 (768 tests).Review rounds
HtmlStreamEventReceiverWrapperhid the renderer, and the bypass came backimageelements are droppedxmp, wrapper postprocessor, change listener)templateunder an already-unknown output context started a fresh known context.<template></template><math><template><svg><mtext><image src=…>kept theimage, which Chrome builds as an HTMLimg. This affects every sink, including on main, and it reopened 0d2e10d's fail-closed pathimage→imgbypasses already on main: (1)<noscript><svg><noscript></noscript><image src=…>, where a scripting-on browser ends the outernoscriptat the inner end tag, and Chrome fetches the URL; (2) the same fortitle,textarea,noembedandnoframesgiven children by an element policy or an event caller; (3) a table part first in atemplateswitches the browser to a table mode that the tracker modeled as bodytextAreaincluded) is dropped, using constant-time per-name counts. A template context becomes unknown at a table-part start in body mode.testForeignEndTagDoesNotReachOlderHtmlAncestorhad pinned shape (1) as expected output; its expectation now drops the innernoscript, and its comment says whyNot changed, judged acceptable by the reviewers: one hostile-only shape that needs a second pass to settle (
<ul><math><select><xmp>); text dropped in two hostile-only shapes;stylesource that surfaces as double-escaped text insideselect/option/math, which also happens on main.Reported by Irhas Abdul Rosyid (@analisaperlengkapan). The other four bypasses were found in review.
🤖 Generated with Claude Code