Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Trusted Types - use setHTML instead of innerHTML internally #5094

Open
Milestone
@kkmuffme

Description

@kkmuffme

Followup to#4409 and it's PR#4927 which were more like for handling TrustedTypes (TT-agnostic).

With Chrome shipping this API soon (v105https://chromestatus.com/feature/5786893650231296, currently v104) and given the exploits with ".sanitize" (in DomPurify, but also inhttps://developer.mozilla.org/en-US/docs/Web/API/Sanitizer/sanitize, seehttps://web.dev/sanitizer/#api-surface), the TT-agnostic approach currently taken can be insufficient/insecure.

Suggested change:
Instead of using.innerHTML =, jQuery should use.setHTML( ... ) when available (https)/supported by the browser


Advantages:

Disadvantages:

  • breaking change for users that used insecure "onclick=",... in their HTML attributes inserted with .html()/.append(),... (which are incompatible with strict CSP policies anyway though) - this is the cost of XSS mitigation though.

Additional discussion needed:

  1. if a trusted type is passed to a jQuery function, should jQuery continue using .innerHTML (instead of .setHTML())?
  • Pro: the trusted type was sanitized according to the users needs (e.g. with certain elements allowed, that might not be allowed by default)
  • Con: can be insecure (as per above)
  1. how would a user pass Sanitizer options to setHtml when using jQuery .html()/.append()/...? Should there be an option for this at all? (if we would keep using .innerHTML for already Trusted Types, there wouldn't be a need for an option, since the user would just sanitize according to his/her needs before passing to jQuery)

Closing thoughts
The current way Trusted Types are handled in jQuery is potentially insecure and still allows for XSS attacks - running afoul of the purpose of Trusted Types.
Furthermore, this minor change, will help make the web safer for users and life easier for developers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp