Skip to content

Trusted Types integration #789

Open
Open
@koto

Description

@koto

We've outlined what we think would be the HTML integration points needed for Trusted Types. This accompanies HTML#3052 describing the integration with HTML.

Approaches

The current draft spec implements the TT checks at the DOM sinks (JS functions) layer, and then discards the type information, such that TT become invisible to most other Web APIs and algorithms. The upside is that TT are simpler to spec & implement, the downside is that the future sinks might be introduced that skip the TT logic, and re-introduce DOM XSS-proneness. Or that we might have missed some existing algorithms that would bypass TT already. There's also a few of bypasses that require some additional custom protections (e.g. this). Let's call that tt-at-sinks approach.

@annevk proposed an alternative approach - to keep the type information intact such that it can be verified by the algorithms running later on (e.g. when script is to be prepared, check that its URL was a TrustedScriptURL. Let's call that tt-at-primitives approach.

TT-at-sinks

  • Add text node validation steps to the insert algorithm.
    Note: Perhaps this needs to be changed - the checks might be problematic in step 7 of node insert as they can partially fail, and then step 8 doesn't run. Perhaps hook after insertion but pre execution.

  • Changes to Element.setAttribute*. That's to add TT checks for IDL attributes that reflect content attributes with those checks. Currently only explained as a note. This needs some work, but in general the approach is to perform the checks (via relevant global object) that ascertain that TT type checks are performed based, determining the right type for (context object, qualified name) pair. These callouts may be added to set an attribute value algorithm.

  • Changes to set an attribute. Callout to TT when the (element, attr qualified name) needs types (e.g. for iframe.srcdoc). The TT checks will attempt to call the default policy on the attribute value, and might abort the algorithm, or change the attr value.

  • Changes to Attr value setter; do the TT checks when setting a value of the attribute on an element, if (element + attr name) pair requires TT checks. Callout to TT checks can be implemented either in set an existing attribute value, or in change an attribute from an element algorithm. The latter might make the changes to set an attribute above unneccessary.

TT-at-primitives

The changes required in DOM for this approach would be:

  • Add type metadata to Attr and Text nodes. (e.g. allow them to store string or TrustedType).

  • Change the signatures of Element.setAttribute* and other affected DOM APIs to also accept a typed value.

  • Change Attr value getter to stringify the output; also in https://dom.spec.whatwg.org/#concept-element-attributes-get-value (or perhaps introduce a don't stringify argument?)

  • Changes to attribute-related algorithms, similar to ones outlined in TT-at-sinks section. Instead of callouts to TT checks, these would likely assert that a value is of an expected type.

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