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

@evilpie evilpie commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

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 whatwg/html#12533.


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

evilpie commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator Author

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

evilpie commented May 18, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased. Should be ready for review, but can't land before whatwg/html#12533 of course.

@evilpie evilpie marked this pull request as ready for review May 18, 2026 11:30
@evilpie

evilpie commented May 22, 2026

Copy link
Copy Markdown
Collaborator Author

@otherdaniel I would appreciate your review on this!

@noamr

noamr commented May 22, 2026

Copy link
Copy Markdown
Collaborator

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
@evilpie

evilpie commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

I don't really feel confident with the behavior here either, but I do want to try and understand this:

If the whole logic only runs when inserting and thus after sanitization, wouldn't this whole point be moot?

I am not sure what you mean here. Do you think the whole idea of trying to prevent the usage of is is wrong? As in, should an user not be able to block the creation of a custom element, or should it just block the execution of the JS code?

From my point of view we definitely don't want to execute custom element callbacks with a default config, in fact I have landed patches in Firefox which already implement this proposal. But I do think the specification, Chrome and Firefox are probably all different in this area.

@annevk

annevk commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

The problem is not that it executes while parsing, but that the callback fires when connected to the main document. And a null registry is patched at that point during connection. This is very similar to script elements which we also disallow.

@otherdaniel

Copy link
Copy Markdown
Collaborator

If the whole logic only runs when inserting and thus after sanitization, wouldn't this whole point be moot?

I am not sure what you mean here. Do you think the whole idea of trying to prevent the usage of is is wrong? As in, should an user not be able to block the creation of a custom element, or should it just block the execution of the JS code?

No. I meant this as a "proof by contradiction" type argument: Before sanitizing, we run the HTML fragment parsing algorithm + copying nodes into a fragment. If we were sure those steps, any pre-sanitize-core steps in fact, would never call or enque calling constructors, then we could just sanitize as normal and this whole issue wouldn't exist. Not sure that was a particularly compelling argument, so if this is too confusing please just ignore it... :-)

I do think everyone agrees on the desired behaviour here. I think the disagreement is merely about the mechanism, or maybe the spec-ification of the mechanism. If the proposed wording works, I'm happy!


I recently landed a fix on our side, which works by making sure is isn't processed, rather than processing it first and then undoing the effect later. I think all implementations pass all the WPT tests:

(I expect Edge to pass 100% too, as soon as they pick up the patch. They're on a slightly different release cycle than us.)

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