Repository navigation
Sanitize while parsing - #12756
Sanitize while parsing#12756
Conversation
7b105e3 to
e24c23b
Compare
4ff3705 to
8551681
Compare
c374a0b to
e8c7cba
Compare
1d9e935 to
4453c2a
Compare
4453c2a to
931141c
Compare
32e5b9a to
1b77b8d
Compare
Sanitization should take place while performing the adoption agency algorithm, otherwise some nodes can be missed. Since adoption agency often adds an intermediate element, the ReplaceWithChildren directive essentially negates it, while Remove reparents the children into the intermediate element and removes all of them. This is in line with spec changes made as part of whatwg/html#12756 Bug: 498272014 Change-Id: Ieb755555635e197f8ed7daf06a08679a0f2d38c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8250959 Commit-Queue: Noam Rosenthal <nrosenthal@google.com> Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org> Cr-Commit-Position: refs/heads/main@{#1680770}
Sanitization should take place while performing the adoption agency algorithm, otherwise some nodes can be missed. Since adoption agency often adds an intermediate element, the ReplaceWithChildren directive essentially negates it, while Remove reparents the children into the intermediate element and removes all of them. This is in line with spec changes made as part of whatwg/html#12756 Bug: 498272014 Change-Id: Ieb755555635e197f8ed7daf06a08679a0f2d38c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8250959 Commit-Queue: Noam Rosenthal <nrosenthal@google.com> Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org> Cr-Commit-Position: refs/heads/main@{#1680770}
Sanitization should take place while performing the adoption agency algorithm, otherwise some nodes can be missed. Since adoption agency often adds an intermediate element, the ReplaceWithChildren directive essentially negates it, while Remove reparents the children into the intermediate element and removes all of them. This is in line with spec changes made as part of whatwg/html#12756 Bug: 498272014 Change-Id: Ieb755555635e197f8ed7daf06a08679a0f2d38c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8250959 Commit-Queue: Noam Rosenthal <nrosenthal@google.com> Reviewed-by: Daniel Vogelheim <vogelheim@chromium.org> Cr-Commit-Position: refs/heads/main@{#1680770}
1b77b8d to
2eb51b7
Compare
AI reviewReviewed at Blockers
Suggestions
Nits
|
This is sorted. |
|
Sorry about the goose chase. Maybe noamr/web-archeologist#10 will help. AI reviewReviewed at
Suggestions
Nits
|
Removed this note, it's already the case anyway.
Fixed
Fixed
Fixed |
AI feedbackReviewed at 25ae90c, together with web-platform-tests/wpt#62492. Lint passes and the build succeeds. The issues raised in earlier rounds look fixed at this head: the processing-instruction allow-list, the Blockers
Suggestions
Nits
|
AI feedbackReviewed at 53c8837, covering 6624235 and 53c8837 since 25ae90c. Lint passes and the build succeeds. The earlier blockers are addressed. Only sanitizing parses use the inert fragment document now, so Blockers
|
This is an existing issue, I opened #13068, and it's actually something we should fix as part of #798. |
|
Hmm okay. I thought we had resolved those issues, but I guess there's something lingering just for media elements. Can you shorten the proposed commit message somewhat? |
Done (+ rebase, hence the multiple commits) |
… document registry step
…s node document Using the current node (not the adjusted current node) prevents a top-level template in the fragment case from attaching a shadow root to the fragment context element. The declarative shadow root registry now comes from the host's node document, which is the inert document (null registry) when sanitizing.
…onfig from options
- Define elementName in 'sanitizer config allows an attribute'. - Recompute the insertion location after creating an element in 'insert a foreign element', and in the script and template start tag steps, since creating a customized built-in element can run script. Drop the now-unused onlyAddToElementStack parameter. - Only create the fragment in an inert document when sanitizing; otherwise create it in the context's node document as before. - Use a plain insert for the reconstructed element in the adoption agency algorithm, as before. - Give 'sanitize' a normative definition next to the parser sanitizer configuration, and update the security considerations and parseHTML() domintro to describe sanitizing while parsing. - Various wording and formatting nits.
- Look up the custom element registry unconditionally and introduce creationRegistry (registry when the sanitizer action is Keep; otherwise null) so the call to "create an element" no longer carries an inline conditional. Rewrite the note to explain that a null registry is what prevents "create an element" from finding a definition. - Mention processing instructions in the "parser sanitizer configuration" prose.
Sanitize while parsing, instead of parsing into a fragment and then walking it.
The sanitizer configuration is passed into the HTML parser, which consults it wherever it would create or insert a node: disallowed elements are never created or inserted (or are replaced by their children, by redirecting insertions to where the element would have gone), disallowed attributes are dropped before the element is created, and disallowed comments and processing instructions are discarded. The separate post-parse "sanitize" algorithm is gone; the safe variants are expressed by applying their restrictions to the configuration up front.
Consequences of doing this in the parser:
<template>andshadowrootmodesurvive the configuration;<template for>patching as well.Web-observable changes compared to the post-parse sanitizer:
Closes Nodes are made non-inert before sanitizing #12560
Closes Streaming sanitizer support #12543
(See WHATWG Working Mode: Changes for more details.)
/dynamic-markup-insertion.html ( diff )
/parsing.html ( diff )