Skip to content

Add trusted types tests for setAttribute that are not sinks. - #50295

Merged
fred-wang merged 1 commit into
masterfrom
tt-set-event-handle-content-attribute
Jan 28, 2025
Merged

fred-wang merged 1 commit into
masterfrom
tt-set-event-handle-content-attribute

Conversation

@fred-wang

@fred-wang fred-wang commented Jan 27, 2025 •

Copy link
Copy Markdown
Contributor

See w3c/trusted-types#520

Closes w3c/trusted-types#573

We add tests for:

  • Names that don't correspond to any event handler attribute.
  • Names that don't correspond to an event handler attribute on any element.
  • Names that don't correspond to an event handler attribute for the modified element.

See w3c/trusted-types#520

We add tests for:

- Names that don't correspond to any event handler attribute.
- Names that don't correspond to an event handler attribute on any element.
- Names that don't correspond to an event handler attribute for the modified element.

@annevk annevk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @fred-wang, this looks great. I hope you don't mind I'm going to use this PR as a check-in on the overall semantics.

Also copying @mozfreddyb and @otherdaniel for that.

[
// The following names correspond to event handler content attributes, but
// not for the div element. The current version of the spec says we should
// still run the default policy on them.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems a bit weird on reflection, but I guess it's okay?

@domenic as you have dabbled a bit in event handler attributes I wonder what you make of the situation with Trusted Types (and soon the Sanitizer API). I guess there's these four classes:

  1. Elements and event handler content attributes defined for them
  2. Elements and event handler content attributes not defined for them (a couple are only defined for the body or media elements)
  3. Elements and event handler content attributes that don't exist, but the event handler attribute does exist somewhere
  4. Elements and event handler content attributes that don't exist, and there's no event handler attribute either

It seems that we're currently leaning towards treating 1 and 2 as something we need to apply policy toward and 3 and 4 as cases we can ignore.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be really specific here, I believe 1 and 2 are consistent across browsers as being protected, 3 is something this test prohibits but implementations actually do protect against[1]. 4. is something that all browsers agree aren't protected.

[1] I'm not familiar with Firefox's implementation here but it seems to protect onreadystatechange for example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding 3, Firefox protects "onreadystatechange" but not "onopen", so that's probably an implementation bug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fred-wang Did you / Can you please file a bug to make sure this isn't lost?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding 2, one simple refinement could be to not do the event handler check if the element is not in the HTML, SVG or MathML namespace: w3c/trusted-types#520

@fred-wang
fred-wang merged commit 6fa87d2 into master Jan 28, 2025
@fred-wang
fred-wang deleted the tt-set-event-handle-content-attribute branch January 28, 2025 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test for event handler content attribute handling for false positive event handler attributes

6 participants