Skip to content

Remove custom element state when is attribute is blocked#396

Open
evilpie wants to merge 4 commits into
WICG:mainfrom
evilpie:is-attribute
Open

Remove custom element state when is attribute is blocked#396
evilpie wants to merge 4 commits into
WICG:mainfrom
evilpie:is-attribute

Conversation

@evilpie
Copy link
Copy Markdown
Collaborator

@evilpie evilpie commented Apr 16, 2026

This depends on changes in #385 that haven't happened yet.

I am not really certain if there isn't some other data structure that we need to patch for this. Presumably this would be easier to specify when we do streaming parsing.

Fixes #387.


Preview | Diff

Comment thread index.bs Outdated
Comment thread index.bs Outdated
@otherdaniel
Copy link
Copy Markdown
Collaborator

Looks good editorially, but I wonder whether this would execute the custom element constructor during parsing?

As I understand this, this would create the custom element, and then later remove it again. If so, I'd expect this to execute the custom element's constructor, and thus bypass sanitization in a sense.

@evilpie
Copy link
Copy Markdown
Collaborator Author

evilpie commented Apr 29, 2026

Looks good editorially, but I wonder whether this would execute the custom element constructor during parsing?

As I understand this, this would create the custom element, and then later remove it again. If so, I'd expect this to execute the custom element's constructor, and thus bypass sanitization in a sense.

No it doesn't AFAIK. The custom constructor (if not removed) is only invoked when inserting. IIRC because the custom elements registry is null for those documents we use for parsing?

You can actually try this out with div.setHTML('<div is="custom-div"></div>') in Firefox Nightly.

@evilpie
Copy link
Copy Markdown
Collaborator Author

evilpie commented May 18, 2026

Rebased. Should be ready for review, but can't land before #387 of course.

@evilpie evilpie marked this pull request as ready for review May 18, 2026 11:30
@evilpie
Copy link
Copy Markdown
Collaborator Author

evilpie commented May 22, 2026

@otherdaniel I would appreciate your review on this!

@noamr
Copy link
Copy Markdown
Collaborator

noamr commented May 22, 2026

Maybe wait with this until after the upstream?

lando-worker Bot pushed a commit to mozilla-firefox/firefox that referenced this pull request May 22, 2026
@otherdaniel
Copy link
Copy Markdown
Collaborator

Looks good editorially, but I wonder whether this would execute the custom element constructor during parsing?
As I understand this, this would create the custom element, and then later remove it again. If so, I'd expect this to execute the custom element's constructor, and thus bypass sanitization in a sense.

No it doesn't AFAIK. The custom constructor (if not removed) is only invoked when inserting. IIRC because the custom elements registry is null for those documents we use for parsing?

You can actually try this out with div.setHTML('<div is="custom-div"></div>') in Firefox Nightly.

To be honest, I'm still a little confused here.

So... the way I read the specs, I'd still expect your example of div.setHTML('<div is="custom-div"></div>') to throw the custom-div constructor (if it's indeed a registered custom element for the document of that initial div).

As an additional point.. if the HTML fragment parsing algorithm doesn't run the custom element constructor anyhow, then why do we even bother with this whole thing? My understanding is that the sanitizer algorithm sits between the parsing and insertion in the document. If the whole logic only runs when inserting and thus after sanitization, wouldn't this whole point be moot?


As said above... I find the whole thing confusing, and am not very confident in my analysis above.

Our implementation seems to slightly deviate from what I find in the specs, in that a custom element registry is expressedly passed in to the parser, and when |scripting mode| is Inert that registry is forced to null. My gut feeling is that this is the better way: If we can guarantee that the parser doesn't execute custom element script during parsing (in this context), then that seems more reliable than fixing this up afterwards.

moz-wptsync-bot pushed a commit to web-platform-tests/wpt that referenced this pull request May 23, 2026
Implements WICG/sanitizer-api#396

Differential Revision: https://phabricator.services.mozilla.com/D301304

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=2040656
gecko-commit: d8f0a20748554395560938baabeaa80986c758cc
gecko-commit-git: beca389380ebb98e7631ffc4c3f06e55d765b009
gecko-reviewers: emilio
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request May 26, 2026
…ute is blocked. r=emilio

Implements WICG/sanitizer-api#396

Differential Revision: https://phabricator.services.mozilla.com/D301304

UltraBlame original commit: d8f0a20748554395560938baabeaa80986c758cc
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request May 26, 2026
…ute is blocked. r=emilio

Implements WICG/sanitizer-api#396

Differential Revision: https://phabricator.services.mozilla.com/D301304

UltraBlame original commit: d8f0a20748554395560938baabeaa80986c758cc
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request May 26, 2026
…ute is blocked. r=emilio

Implements WICG/sanitizer-api#396

Differential Revision: https://phabricator.services.mozilla.com/D301304

UltraBlame original commit: d8f0a20748554395560938baabeaa80986c758cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The is non-attribute allows custom elements to sneak in

4 participants