Skip to content

Finalise spec mechanism for event handlers #520

Open

Description

@lukewarlow

As of #457 the spec uses the HTML "event handler content attribute" concept. Anne's feedback was that that was ambiguous and we should instead generate a fixed list to check inside of. This issue tracks generating that or an alternative.

cc @koto as spec editor you might know how best to deal with this.

Activity

  1. added this to the v1 milestone on Jun 12, 2024
  2. koto commented on Jun 28, 2024

    @koto
    Member

    @otherdaniel how does Sanitizer deal with this? From memory, the challenge was that there was no centralized and specced list of event handlers we could refer to.

  3. otherdaniel commented on Jun 28, 2024

    @otherdaniel
    Member

    @otherdaniel how does Sanitizer deal with this? From memory, the challenge was that there was no centralized and specced list of event handlers we could refer to.

    Yes, there isn't a spec list of event handlers. Sanitizer has it a bit easier, since it's based on an allow-list: We (manually) write a list of allowed attributes, and we maintain a list of all attributes. Sanitizer doesn't have to decide why an attribute (or element) isn't in the allow-list, e.g. whether it's an event handler or not.

    There was some discussion of adding some sort of spec-level 'tags' to any known element or attribute that could then form a basis for these lists; but this mechanism doesn't currently exist. Until it does, it'll be manually maintained lists.

  4. lukewarlow commented on Jun 28, 2024

    @lukewarlow
    MemberAuthor

    I'm happy to spend some time and put together a list.

    But from a spec maintainer and implementation point of view a block list of element event handler attributes seems far from ideal. Any time someone adds a new one they have to remember to adjust that list. Rather than current implementations which just use the IDL (which I'm realistically gonna use as the basis for my list). Especially tricky if the event handler is specified in a random wicg spec or something like that. Also if there's non standard events browsers have they should also be protected but won't be specced.

    That being said I'm happy to defer to others on whether that's okay in practice.

  5. koto commented on Jun 28, 2024

    @koto
    Member

    So, rephrasing, the choice is to be either ambiguous and refer to other spec concepts (event handler content attribute), or explicit, and maintain a separate list (here, or in HTML?). I actually think the first choice is better, from normative perspective.

  6. otherdaniel commented on Jun 28, 2024

    @otherdaniel
    Member

    But from a spec maintainer and implementation point of view a block list of element event handler attributes seems far from ideal.

    From an implementation point of view, there's two easy ways:

    • Check whether the attribute name [Edit: of a spec-defined attribute] starts with "on". HTML has been quite consistent with that.
    • All event handlers in WebIDL are of type EventHandler, OnBeforeUnloadEventHandler, or OnErrorEventHandler.

    But I don't think this is how we can spec things.

  7. lukewarlow commented on Jun 28, 2024

    @lukewarlow
    MemberAuthor

    check whether the attribute name starts with "on". HTML has been quite consistent with that

    Unfortunately custom attributes would fall foul of that and apparently chrome's had issues with it.

  8. otherdaniel commented on Jun 28, 2024

    @otherdaniel
    Member

    check whether the attribute name starts with "on". HTML has been quite consistent with that

    Unfortunately custom attributes would fall foul of that and apparently chrome's had issues with it.

    What I meant is, whether it's a spec-defined attribute and starts with "on". Getting a list of attributes described in the spec and filtering for the "on" prefix gets you the list of event handler attributes, as they've been consistent with the naming.

  9. annevk commented on Jul 1, 2024

    @annevk
    Member

    "Specification-defined attribute" is also not a concept that exists though, currently.

  10. fred-wang commented on Oct 22, 2024

    @fred-wang
    Collaborator

    Skimming over existing WPT tests, it seems all the event handler attributes used in tests are coming from GlobalEventHandlers. Conversely, all event handler attributes from GlobalEventHandlers are covered by trusted-types-event-handlers.html (which tries all the names of a div's proto starting with 'on' of at least 3 characters)

    Trying to implement getAttributeType in Firefox, it's not clear from the current text of the spec whether the attributes below should also be covered:

    • WindowEventHandlers from the on HTMLBodyElement and HTMLFrameSetElement, some of them also supported by the <svg> element.
    • onencrypted and onwaitingforkey on HTMLMediaElement from the Encrypted Media Extensions.
    • SMIL attributes used for SVG animations (namely onbegin, onend and onrepeat).
  11. 1 remaining item

  12. fred-wang commented on Jan 14, 2025

    @fred-wang
    Collaborator
  13. annevk commented on Jan 14, 2025

    @annevk
    Member

    @fred-wang that's great to see! Could you also add tests for event handlers that are not event handler content attributes? E.g., onreadystatechange, onopen, and ondoesnotexist.

    cc @lukewarlow

  14. fred-wang commented on Jan 27, 2025

    @fred-wang
    Collaborator
  15. fred-wang commented on Feb 3, 2025

    @fred-wang
    Collaborator

    @annevk @lukewarlow One thing that I have been wondering for a while, is whether we should make the "Get Trusted Type data for attribute" a bit more restrictive and only test for "event handler content attribute" if the element is in the HTML, SVG or MathML namespace?

  16. annevk commented on Feb 25, 2025

    @annevk
    Member

    @fred-wang that sounds good to me given that GlobalEventHandlers is not included by Element at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions