w3c / trusted-types

A browser API to prevent DOM-Based Cross Site Scripting in modern web applications.
https://w3c.github.io/trusted-types/dist/spec/
Other
606 stars 74 forks source link

Add WPT for "create navigation params by fetching" step 19.3 #547

Closed mbrodesser-Igalia closed 1 month ago

mbrodesser-Igalia commented 2 months ago

No WPT for https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching step 19.3 exists.

It's relevant for TT because above step calls [1] and that calls [2].

CC @otherdaniel, @lukewarlow

[1] https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching [2] https://www.w3.org/TR/trusted-types/#require-trusted-types-for-pre-navigation-check

otherdaniel commented 1 month ago

As I read this:

This handles the TT check for javascript:-navigations.

The tests should be here: https://github.com/web-platform-tests/wpt/blob/master/trusted-types/trusted-types-navigation.html

Note that much of the logic is in the support file, support/navigation-support.html. (The test sets up a frame, and then navigates that frame to various URLs. Most of the logic is thus within the frame.) Those tests cover both window.open cases and navigating a frame, with and without default policy.

When I break the corresponding TT logic in Chrome and re-run the test, they indeed fail (with timeouts), so I think those tests are effective. (Unfortunately, the navigation logic in Chrome is spread out quite a bit, so it's a bit difficult to determine whether this handles all suitable combinations; but they do seem to cover the major cases.)

mbrodesser-Igalia commented 1 month ago

As I read this:

* https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching

* calls into https://w3c.github.io/webappsec-csp/#should-block-navigation-request

* which is monkey-patched here:  https://www.w3.org/TR/trusted-types/#require-trusted-types-for-pre-navigation-check

This handles the TT check for javascript:-navigations.

javascript:-navigations are handled by

and tested by: https://github.com/web-platform-tests/wpt/blob/master/trusted-types/trusted-types-navigation.html.

The call path

is another one. It's unclear to me to which concrete scenarios the latter call path corresponds to.

mbrodesser-Igalia commented 1 month ago

Only step 5.2 of https://html.spec.whatwg.org/multipage/browsing-the-web.html#attempt-to-populate-the-history-entry's-document conditionally calls https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching for "fetch schemes" (https://fetch.spec.whatwg.org/#fetch-scheme).

Since javascript: is not a fetch scheme, Trusted Types pre-navigation check (https://www.w3.org/TR/trusted-types/#require-trusted-types-for-pre-navigation-check) will return early as a no-op. So there's no Trusted Types specific scenario to be tested which exercises https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching.

otherdaniel commented 1 month ago

Sorry for being a bit late; but just wanted to confirm your reading: I think you're right that the existing TT tests don't cover this code path; but also that it's a no-op for TT since this bit is only being called for "fetch schemes".