Sanitizing while parsing keeps the form owner of a replaced form and loses declarative shadow DOM on a replaced host
Categories
(Core :: DOM: HTML Parser, defect)
Tracking
()
People
(Reporter: zcorpan, Unassigned)
References
(Blocks 1 open bug)
Details
(Findings by Claude Code, Opus 5.5, high effort.)
I found these while reviewing bug 2062652 against https://github.com/whatwg/html/pull/12756 (at 53c8837), with dom.security.sanitizer.while-parsing enabled. I ran the sanitizer-api tests from https://github.com/web-platform-tests/wpt/pull/62492.
- When a
formis replaced with its children, its controls still get it as their form owner.
Document.parseHTMLUnsafe("<form id=f><input></form>", {sanitizer: {replaceWithChildrenElements: ["form"]}})
Here input.form is the detached <form id="f">, but the spec expects null: the insertion target redirection map has an entry for the form element pointer's element. The nsHtml5TreeBuilder::createElement overload that takes aFormElement calls nsHtml5TreeOperation::SetFormElement without checking for this. sanitizer-api/sethtml-form-owner.html fails on this.
- A declarative shadow root whose host is replaced with its children is attached to that host, so its content is lost.
Document.parseHTMLUnsafe("<div><template shadowrootmode=open>s</template>x</div>", {sanitizer: {replaceWithChildrenElements: ["div"]}}).body.innerHTML
Fx returns x; the spec expects <template shadowrootmode="open">s</template>x (the template goes where the host's children go). appendToCurrentNodeAndPushTemplateElement only checks the sanitizer action for the template itself, not its host. The WPT test for this passes only because of 3.
-
With a sanitizer,
setHTML()andsetHTMLUnsafe()(SetAndFilterHTML) passNothing()as the custom element registry, andnsContentUtils::ParseFragmentHTMLalways disallows declarative shadow roots. ThesetHTMLUnsafe()path without a sanitizer passes both. As a result, allowed custom elements aren't constructed before the call returns, scoped registries are ignored, and no declarative shadow roots are created. Tests fail insethtml-with-custom-elements.html,sanitizer-custom-elements-constructor.htmlandsethtml-with-declarative-shadow-root.html. This predates bug 2062652. When the registry gets passed through,createElementalso needs to skip the custom element definition for elements the sanitizer removes or replaces with their children, since the spec gives those a null registry. Today the missing registry hides that. -
Some comments no longer match the spec.
SanitizerState::SanitizeMergedAttributesandaddAttributesToElementsay the spec re-sanitizeshtml/bodyafter merging attributes and asserts "Keep"; the PR filters each token attribute before merging instead. Comments inSanitizer.cpp,nsContentUtils.h,nsHtml5StringParser.cppandnsHtml5TreeBuilderHSupplement.hcite "sanitize an Element", "remove javascript navigation URLs" and the#sanitizeanchor, none of which are in the PR anymore.
Updated•1 month ago
|
Comment 1•1 month ago
|
||
The severity field is not set for this bug.
:jjaschke, could you have a look please?
For more information, please visit BugBot documentation.
Updated•1 month ago
|
Description
•