Support sanitization using <template for="..." sanitize> [chromium/src : main]

0 views
Skip to first unread message

Noam Rosenthal (Gerrit)

unread,
Jul 27, 2026, 12:36:35 PM (5 days ago) Jul 27
to AI Code Reviewer, Chromium LUCI CQ, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, android-web...@chromium.org, ashleynewson+watch-...@chromium.org, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org, loading-rev...@chromium.org

Noam Rosenthal added 1 comment

File third_party/blink/renderer/core/html/parser/patch.h
Line 29, Patchset 1: StreamingSanitizer* sanitizer() const { return sanitizer_.Get(); }
AI Code Reviewer . resolved

nit: Blink Style Guide: Naming - Use 'CamelCase' for all function names, and prefix with 'Get' if the name collides with a type name. Consider renaming this getter to `GetSanitizer()` since `Sanitizer` is an existing class name.

To keep this interaction as brief and non-intrusive as possible, please consider responding with one of following options:
**Done** | **OK But Won't Fix**: reason | **Later**: b/<bug_id> | **Invalid:** reason


_This comment was generated by [Experimental Blink C++ Code Review Agent](http://go/blink-c++-code-review-agent)._
_AI reviews can sometimes be inaccurate; We appreciate your 🙏 feedback 🙏 to help us improve._
_[File a bug](http://go/blink-c++-code-review-agent-feedback) | [Provide feedback on chat](https://chat.google.com/room/AAQA0zhQHe0?cls=4) | [Opt-out](https://ganpati2.corp.google.com/group/peep-genai-blink-agent-optout.prod)_

Noam Rosenthal

Acknowledged

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I2e9b4f5753e4043cff348ff2b975d1f1f3f73e0e
Gerrit-Change-Number: 8125134
Gerrit-PatchSet: 3
Gerrit-Owner: Noam Rosenthal <nrose...@google.com>
Gerrit-Reviewer: Noam Rosenthal <nrose...@google.com>
Gerrit-CC: AI Code Reviewer <peep-gen...@system.gserviceaccount.com>
Gerrit-Comment-Date: Mon, 27 Jul 2026 16:36:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: AI Code Reviewer <peep-gen...@system.gserviceaccount.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Daniel Vogelheim (Gerrit)

unread,
Jul 28, 2026, 12:08:02 PM (4 days ago) Jul 28
to Noam Rosenthal, Daniel Vogelheim, AI Code Reviewer, Chromium LUCI CQ, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, android-web...@chromium.org, ashleynewson+watch-...@chromium.org, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org, loading-rev...@chromium.org
Attention needed from Noam Rosenthal

Daniel Vogelheim added 4 comments

Patchset-level comments
File-level comment, Patchset 6 (Latest):
Daniel Vogelheim . resolved

Generally very happy with this. But I'm weirded out af the syntax of the attribute. By my reading, the empty string is the only (!!) way to actually sanitize?

File third_party/blink/renderer/core/html/parser/html_construction_site.cc
Line 473, Patchset 6 (Latest):bool HTMLConstructionSite::SanitizeIfNeeded(HTMLConstructionSiteTask& task) {
Daniel Vogelheim . unresolved

I find it difficult to reason about what the boolean return parameter means here. Maybe add a comment? (here, or in the header)

File third_party/blink/renderer/core/html/parser/patch.cc
Line 65, Patchset 6 (Latest): if (sanitize_val.empty()) {
Daniel Vogelheim . unresolved

Not sure if I'm reading this correctly... If we have no 'sanitize' attribute, or if we have an attribute with any content (other than the empty string) sanitizer will remain nullptr?

I think the test cases support this intent, but I find it weird...

  • `<template for sanitize>` => default sanitization
  • `<template for>` => no sanitization
  • `<template for sanitize="unsafe">` => also no sanitization
  • `<template for sanitize="super duper extra safe">` => also no sanitization.
  • `<template for sanitize=" ">` => Space? No sanitization.
File third_party/blink/web_tests/external/wpt/html/dom/partial-updates/tentative/fragment/sanitize-nested.html
Line 15, Patchset 6 (Latest): <template for="inner-marker-1" sanitize="unsafe">
Daniel Vogelheim . unresolved

... what is this supposed to do?

Open in Gerrit

Related details

Attention is currently required from:
  • Noam Rosenthal
Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: chromium/src
    Gerrit-Branch: main
    Gerrit-Change-Id: I2e9b4f5753e4043cff348ff2b975d1f1f3f73e0e
    Gerrit-Change-Number: 8125134
    Gerrit-PatchSet: 6
    Gerrit-Owner: Noam Rosenthal <nrose...@google.com>
    Gerrit-Reviewer: Daniel Vogelheim <voge...@chromium.org>
    Gerrit-Attention: Noam Rosenthal <nrose...@google.com>
    Gerrit-Comment-Date: Tue, 28 Jul 2026 16:07:43 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Noam Rosenthal (Gerrit)

    unread,
    Jul 29, 2026, 5:22:25 AM (3 days ago) Jul 29
    to Daniel Vogelheim, AI Code Reviewer, Chromium LUCI CQ, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, android-web...@chromium.org, ashleynewson+watch-...@chromium.org, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org, loading-rev...@chromium.org
    Attention needed from Daniel Vogelheim

    Noam Rosenthal added 3 comments

    File third_party/blink/renderer/core/html/parser/html_construction_site.cc
    Line 473, Patchset 6:bool HTMLConstructionSite::SanitizeIfNeeded(HTMLConstructionSiteTask& task) {
    Daniel Vogelheim . resolved

    I find it difficult to reason about what the boolean return parameter means here. Maybe add a comment? (here, or in the header)

    Noam Rosenthal

    Added a comment.

    File third_party/blink/renderer/core/html/parser/patch.cc
    Line 65, Patchset 6: if (sanitize_val.empty()) {
    Daniel Vogelheim . resolved

    Not sure if I'm reading this correctly... If we have no 'sanitize' attribute, or if we have an attribute with any content (other than the empty string) sanitizer will remain nullptr?

    I think the test cases support this intent, but I find it weird...

    • `<template for sanitize>` => default sanitization
    • `<template for>` => no sanitization
    • `<template for sanitize="unsafe">` => also no sanitization
    • `<template for sanitize="super duper extra safe">` => also no sanitization.
    • `<template for sanitize=" ">` => Space? No sanitization.
    Noam Rosenthal

    This is supposed to be a boolean attribute (third_party/blink/web_tests/external/wpt/html/dom/partial-updates/tentative/fragment/sanitize-nested.html)

    So `<template for sanitize>`, `<template for sanitize="">` and `<template for sanitize="sanitize">` should work. I updated the code and examples.

    To be extended later when we have sanitizer presets

    File third_party/blink/web_tests/external/wpt/html/dom/partial-updates/tentative/fragment/sanitize-nested.html
    Line 15, Patchset 6: <template for="inner-marker-1" sanitize="unsafe">
    Daniel Vogelheim . resolved

    ... what is this supposed to do?

    Noam Rosenthal

    Refactored the test to be more concise.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Daniel Vogelheim
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement is not satisfiedCode-Review
      • requirement is not satisfiedReview-Enforcement
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I2e9b4f5753e4043cff348ff2b975d1f1f3f73e0e
      Gerrit-Change-Number: 8125134
      Gerrit-PatchSet: 9
      Gerrit-Owner: Noam Rosenthal <nrose...@google.com>
      Gerrit-Reviewer: Daniel Vogelheim <voge...@chromium.org>
      Gerrit-Reviewer: Noam Rosenthal <nrose...@google.com>
      Gerrit-CC: AI Code Reviewer <peep-gen...@system.gserviceaccount.com>
      Gerrit-Attention: Daniel Vogelheim <voge...@chromium.org>
      Gerrit-Comment-Date: Wed, 29 Jul 2026 09:22:05 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Daniel Vogelheim <voge...@chromium.org>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Daniel Vogelheim (Gerrit)

      unread,
      Jul 31, 2026, 8:24:06 AM (18 hours ago) Jul 31
      to Noam Rosenthal, Daniel Vogelheim, AI Code Reviewer, Chromium LUCI CQ, android-bu...@system.gserviceaccount.com, chromium...@chromium.org, android-web...@chromium.org, ashleynewson+watch-...@chromium.org, blink-rev...@chromium.org, blink-revie...@chromium.org, blink-...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org, loading-rev...@chromium.org
      Attention needed from Noam Rosenthal

      Daniel Vogelheim voted and added 4 comments

      Votes added by Daniel Vogelheim

      Code-Review+1

      4 comments

      Patchset-level comments
      File-level comment, Patchset 12 (Latest):
      Daniel Vogelheim . resolved

      Looks good, but some nitpicks.

      File third_party/blink/renderer/core/html/parser/html_construction_site.cc
      Line 488, Patchset 12 (Latest): for (HTMLStackItem* item = open_elements_.TopStackItem(); item;
      Daniel Vogelheim . unresolved

      This "smells" like a O(n*log n) algo, since it would seem to walk up the stack of elements, on potentially every element. It might be worth checking what this does to performance on large HTML strings being streamed.

      But then... perf analysis by "looking at code" tends to not be very reliable, so I'll leave it to you whether this needs more work or not.

      Line 1211, Patchset 12 (Latest): bool sanitizer_allows_is_attribute = true;
      if (auto* active_sanitizer = ActiveSanitizer()) {
      sanitizer_allows_is_attribute =
      active_sanitizer->AllowIsAttribute(html_names::kScriptTag);
      }
      Daniel Vogelheim . unresolved

      I think I'd find it slightly more readable if ActiveSanitizer() is assigned to a name first. Like so:

      auto* active_sanitizer = ActiveSanitizer();
      bool sanitizer_allows_is_attribute =
      !active_sanitizer || active_sanitizer->AllowIsAttribute(html_names::kScriptTag);

      (That's just personal preference, however. Proceed as you see fit.)

      File third_party/blink/web_tests/external/wpt/html/dom/partial-updates/tentative/fragment/sanitize-boolean.html
      Line 22, Patchset 12 (Latest): <template for="marker-empty-val" sanitize="">
      Daniel Vogelheim . unresolved

      Maybe also a test case with " " (i.e., non-empty, but only whitespace)?

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Noam Rosenthal
      Submit Requirements:
        • requirement satisfiedCode-Coverage
        • requirement satisfiedCode-Owners
        • requirement satisfiedCode-Review
        • requirement is not satisfiedNo-Unresolved-Comments
        • requirement satisfiedReview-Enforcement
        Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
        Gerrit-MessageType: comment
        Gerrit-Project: chromium/src
        Gerrit-Branch: main
        Gerrit-Change-Id: I2e9b4f5753e4043cff348ff2b975d1f1f3f73e0e
        Gerrit-Change-Number: 8125134
        Gerrit-PatchSet: 12
        Gerrit-Owner: Noam Rosenthal <nrose...@google.com>
        Gerrit-Reviewer: Daniel Vogelheim <voge...@chromium.org>
        Gerrit-Reviewer: Noam Rosenthal <nrose...@google.com>
        Gerrit-CC: AI Code Reviewer <peep-gen...@system.gserviceaccount.com>
        Gerrit-Attention: Noam Rosenthal <nrose...@google.com>
        Gerrit-Comment-Date: Fri, 31 Jul 2026 12:23:46 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: Yes
        satisfied_requirement
        unsatisfied_requirement
        open
        diffy
        Reply all
        Reply to author
        Forward
        0 new messages