Skip to content

Conflicting SRI test cases for integrity checks and cross-origin hosts. #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TimvdLippe opened this issue May 29, 2025 · 3 comments · Fixed by servo/servo#37154 or web-platform-tests/wpt#52850

Comments

@TimvdLippe
Copy link
Contributor

We are implementing the post-request check in Servo: servo/servo#37154 Based on our investigation, no other browser currently implements this check: servo/servo#37154 (comment)

After implementation, we ran into test failures in tests/wpt/tests/content-security-policy/default-src/default-src-sri_hash.sub.html. This test appears to verify the various integrity checks. We realized that the domain was wrong, where the test was using {{domain[www]}}, where the actual current domain is {{domain[]}}. That fixed a bunch of test cases for us.

However, now there are still test failures related to integrity matching. I see that this most recently was changed in #654. If I follow the logic for the following test case:

[ 'no integrity',
  './simpleSourcedScript.js',
  '',
  false ],

When we run https://www.w3.org/TR/CSP/#script-post-request on this:

1.2. We don't have a nonce, so continuing
1.3. We don't match integrity (since it is empty/not set)
1.4. We don't have strict-dynamic included
1.5. This response is allowed, since it is a same-origin request (it matches the host)

Hence we run into step 2, where we return allowed.

When I read the test, the intention (and the current browser behavior) is to reject this request. Relevant implementations:

  • Chromium
  • Gecko
  • (Can't find WebKit as they don't use comments to refer to specs)

Based on the intention, I thought that #654 was the wrong way around, e.g. it should have been this:

If the result of executing § 6.7.2.4 Does integrity metadata match source list? on request’s integrity metadata and this directive’s value is "Does Not Match", return "Blocked".

That works for this particular test, but then we get to the actual post-request check failing a different test case:

[ 'crossorigin no integrity but allowed host',
  crossorigin_base + '/content-security-policy/script-src/crossoriginScript.js',
  '',
  true ],

E.g. this test now does the exact opposite: if the host matches, regardless of the integrity it should load it.

Given that no other browser implements this check yet, I am not sure what the correct behavior should be. I think updating the integrity check to "Does Not Match" is correct, but then what should we do with the crossorigin test case?

@TimvdLippe
Copy link
Contributor Author

Tentative WPT PR with the test updates: web-platform-tests/wpt#52850

@TimvdLippe
Copy link
Contributor Author

I just realised that the test and algorithm is probably correct after all. While investigating I saw that the Rust CSP crate was missing a check. This weekend I can debug more and confirm whether my current understanding is correct. If so, I will add comments to the test to make it more descriptive of what's going on.

TimvdLippe pushed a commit to TimvdLippe/servo that referenced this issue May 30, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo#36760
Fixes servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
@TimvdLippe
Copy link
Contributor Author

My realisation is correct. The test is correct and the specification as well. The reason I got things mixed up, is that the CSP crate was missing the integrity check and then the test started failing in confusing ways. I have added clarifying comments to the test, to make a future reader aware of the nuances of the {{domain[www]}}.

servo-wpt-sync pushed a commit to servo/wpt that referenced this issue May 30, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
TimvdLippe pushed a commit to TimvdLippe/servo that referenced this issue May 30, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo#36760
Fixes servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
servo-wpt-sync pushed a commit to servo/wpt that referenced this issue May 30, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
TimvdLippe added a commit to TimvdLippe/webappsec-csp that referenced this issue May 30, 2025
It was inconsistent with the pre-request check with regards to the
handling of `strict-dynamic` in both case-sensitivity and parser
metadata.

Additionally, add a clarifying comment about why the post-request
check also checks the request, to avoid confusion for implementers.

Fixes w3c#727 
Part of w3c#728
TimvdLippe pushed a commit to TimvdLippe/servo that referenced this issue May 31, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo#36760
Fixes servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
servo-wpt-sync pushed a commit to servo/wpt that referenced this issue May 31, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
TimvdLippe pushed a commit to TimvdLippe/servo that referenced this issue May 31, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo#36760
Fixes servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
servo-wpt-sync pushed a commit to servo/wpt that referenced this issue May 31, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
github-merge-queue bot pushed a commit to servo/servo that referenced this issue May 31, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes #37200
Closes #36760
Fixes #36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728
Part of #4577

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
Co-authored-by: Josh Matthews 
servo-wpt-sync pushed a commit to servo/wpt that referenced this issue Jun 1, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
servo-wpt-sync pushed a commit to web-platform-tests/wpt that referenced this issue Jun 1, 2025
Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 
lando-prod-mozilla bot pushed a commit to mozilla-firefox/firefox that referenced this issue Jun 6, 2025
…es.,

Automatic update from web-platform-tests
net: Perform CSP checks on fetch responses.

Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 

--

wpt-commits: 17e2e028455d9f86ae9a428fccb292b354d89ed6
wpt-pr: 52850

Differential Revision: https://phabricator.services.mozilla.com/D252812
antosart pushed a commit that referenced this issue Jun 6, 2025
It was inconsistent with the pre-request check with regards to the
handling of `strict-dynamic` in both case-sensitivity and parser
metadata.

Additionally, add a clarifying comment about why the post-request
check also checks the request, to avoid confusion for implementers.

Fixes #727 
Part of #728
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jun 6, 2025
…es.,

Automatic update from web-platform-tests
net: Perform CSP checks on fetch responses.

Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 

--

wpt-commits: 17e2e028455d9f86ae9a428fccb292b354d89ed6
wpt-pr: 52850

Differential Revision: https://phabricator.services.mozilla.com/D252812
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Jun 7, 2025
…es.,

Automatic update from web-platform-tests
net: Perform CSP checks on fetch responses.

Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 

--

wpt-commits: 17e2e028455d9f86ae9a428fccb292b354d89ed6
wpt-pr: 52850

Differential Revision: https://phabricator.services.mozilla.com/D252812
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Jun 11, 2025
…es.,

Automatic update from web-platform-tests
net: Perform CSP checks on fetch responses.

Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 

--

wpt-commits: 17e2e028455d9f86ae9a428fccb292b354d89ed6
wpt-pr: 52850

Differential Revision: https://phabricator.services.mozilla.com/D252812

UltraBlame original commit: e03bfa632ece2cf90574e7b2be50b8f42763bbe7
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Jun 11, 2025
…es.,

Automatic update from web-platform-tests
net: Perform CSP checks on fetch responses.

Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 

--

wpt-commits: 17e2e028455d9f86ae9a428fccb292b354d89ed6
wpt-pr: 52850

Differential Revision: https://phabricator.services.mozilla.com/D252812

UltraBlame original commit: e03bfa632ece2cf90574e7b2be50b8f42763bbe7
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Jun 11, 2025
…es.,

Automatic update from web-platform-tests
net: Perform CSP checks on fetch responses.

Also add clarifying comments to the SRI WPT tests with
regards to the `www.` domain and how that interacts with
the integrity checks.

Lastly, adjust the casing for `Strict-Dynamic`, as in
the post-request check that should also be case-insensitive.

Closes servo/servo#36760
Fixes servo/servo#36499
Part of w3c/webappsec-csp#727
Fixes w3c/webappsec-csp#728

Signed-off-by: Josh Matthews 
Signed-off-by: Tim van der Lippe 

--

wpt-commits: 17e2e028455d9f86ae9a428fccb292b354d89ed6
wpt-pr: 52850

Differential Revision: https://phabricator.services.mozilla.com/D252812

UltraBlame original commit: e03bfa632ece2cf90574e7b2be50b8f42763bbe7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants
@TimvdLippe and others