Skip to content

Custom element registry can call constructor of sanitizer-removed elements #381

@noamr

Description

@noamr

Envision the following script:

const scoped_registry = new CustomElementRegistry();
scoped_registry.define("forbidden-element", class ForbiddenElement : HTMLElement { 
  constructor() {
    super();
    console.log("This should not be called");
  }
});

const container = document.createElement("div", {customElementRegistry: scoped_registry });
container.setHTMLUnsafe(
  "<forbidden-element></forbidden-element>", {
  sanitizer: {removeElements: ["forbidden-element"]}
});

According to the current spec, the console would log "This should not be called".

That is because:

  • the sanitizer API calls the fragment parser
  • In turn, the fragment parser uses the custom element registry of the context element
  • Parsing happens before sanitization
  • Custom element constructors happen straight away when an element is created.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions