Sanitize while parsing - #12756
Sanitize while parsing#12756noamr wants to merge 2 commits into
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
b202606 to
16572fe
Compare
0c49f36 to
ca03f6d
Compare
745e3da to
4f7d932
Compare
b9c7562 to
202ffa5
Compare
202ffa5 to
1b12170
Compare
|
From web-platform-tests/wpt#62492 (comment)
The relevant test was: Any thoughts on what should happen here? |
|
The above comment was from an older revision of this PR, and the current revision should produce For the exact wpt case they agree, but only by coincidence, and the two use different mechanisms that diverge as soon as the inner loop does any work.
case Sanitizer::Action::kReplaceWithChildren:
// Skip DOM operations. Children safely remain in furthest_block.
continue;
case Sanitizer::Action::kDrop:
tree_.TakeAllChildren(new_item, furthest_block);
break;
case Sanitizer::Action::kKeep:
case Sanitizer::Action::kKeepElement:
tree_.TakeAllChildren(new_item, furthest_block);
tree_.Reparent(furthest_block, new_item);
break;So In
Canary: Spec at With Canary looks right to me: the plain parse of that input puts the Edit: fixed in 5452f09 |
|
One more divergence from Chromium:
After 8 iterations The spec as written gives: (In a normal parse, "Textafter" is one text node in More generally, the map entry of any replaced-with-children element directly below I think the fix is to update the entries for the run of replaced elements immediately below Edit: fixed in 16e9bb5 |
|
A few more issues found by Claude: AI reviewHere's the consolidated picture, with Canary 155.0.8059.0 as the reference and each item verified by trace against the spec at 16e9bb5. Spec problems
Chromium bugs, spec looks right
Both agree, but differ from parse-then-sanitize
Everything else the forks tried matched: all AAA Remove paths, reconstruction, Edit: 3 spec issues fixed. |
…onary member access * When the sanitizer replaces an element with its children, the element is never inserted. A declarative shadow root attached to it would be lost, and attaching could throw for elements that can't be shadow hosts. Such a <template shadowrootmode> is now inserted as a regular template element, where the replaced element's children go. * "Sanitizer config allows an attribute": the configuration's removeAttributes member is optional, so check that it exists before testing whether it contains the attribute. Access the members of the SanitizerElementNamespace and SanitizerAttributeNamespace dictionaries with map syntax (attrName["name"]) instead of attrName's name.
Instead of parsing into a fragment and then statically sanitizing that fragment, sanitize as we parse.
This entails the following changes:
javascriptURLs), so the parser only needs the configuration itself.DocumentFragment, and also to redirect elements to their nearest non-replaced ancestor when a child is stripped but its children are kept. The adoption agency algorithm updates the entries of replaced elements it moves.isattribute the sanitizer would remove is ignored.Closes #12560
Closes #12543
(See WHATWG Working Mode: Changes for more details.)
/dynamic-markup-insertion.html ( diff )
/parsing.html ( diff )