Skip to content
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

Perform a CSP check when consuming preloaded response #1411

Merged
merged 9 commits into from
Mar 17, 2022

Conversation

noamr
Copy link
Contributor

@noamr noamr commented Mar 10, 2022

Closes whatwg/html#7686

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@annevk
Copy link
Member

annevk commented Mar 11, 2022

From the discussion in that HTML issue this doesn't seem like the correct fix as the other policies (e.g., Mixed Content blocking) do not end up being enforced.

@noamr
Copy link
Contributor Author

noamr commented Mar 11, 2022

From the discussion in that HTML issue this doesn't seem like the correct fix as the other policies (e.g., Mixed Content blocking) do not end up being enforced.

Unless I am missing something, the other policies are not modifiable after the document is created, so there is no need to re-check them. That's true at least for mixed content and was discussed in the HTML issue.

@annevk
Copy link
Member

annevk commented Mar 11, 2022

  • It seems that "Run report Content Security Policy violations for request" wouldn't happen.
  • Mike's scenario of scheme upgrades seems problematic. Yes, perhaps there's an HTTP cache entry, but is that guaranteed? And either way, wouldn't it result in a service worker being asked whereas if the scheme upgrade happened before that wouldn't be the case? (Scheme upgrades is also what Mixed Content Level 2 does.)

I haven't done a complete check, but this seems concerning and also suggests a potential mismatch with implementations that might cause further issues in the future.

@noamr
Copy link
Contributor Author

noamr commented Mar 11, 2022

  • It seems that "Run report Content Security Policy violations for request" wouldn't happen.

Does that need to happen again? The request in question had already been processed.

But I agree that this is indeed concerning. Not so much for the preload case where we can define that all the checks happen a second time, but I'm more concerned about other memory cache scenarios that are not clearly specified.

@noamr
Copy link
Contributor Author

noamr commented Mar 11, 2022

  • It seems that "Run report Content Security Policy violations for request" wouldn't happen.
  • Mike's scenario of scheme upgrades seems problematic. Yes, perhaps there's an HTTP cache entry, but is that guaranteed? And either way, wouldn't it result in a service worker being asked whereas if the scheme upgrade happened before that wouldn't be the case? (Scheme upgrades is also what Mixed Content Level 2 does.)

I haven't done a complete check, but this seems concerning and also suggests a potential mismatch with implementations that might cause further issues in the future.

I refactored preload handling - where a preload scenario goes through the same checks as any other fetch, but uses the preloaded response instead of seeking it in network or cache in main fetch. This seems to be the safest, and allows us to incorporate different memory cache scenarios later by folding them into consume a preloaded resource. WDYT?

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

This looks really solid. This would result in reporting twice, right? Is that a case we might want to adjust to not do that or is it fine?

fetch.bs Outdated Show resolved Hide resolved
fetch.bs Show resolved Hide resolved
fetch.bs Outdated Show resolved Hide resolved
@noamr
Copy link
Contributor Author

noamr commented Mar 16, 2022

This looks really solid. This would result in reporting twice, right? Is that a case we might want to adjust to not do that or is it fine?

I think it's ok that it reports twice if both the preload and actual request are in violation but I will add a test to verify

@noamr
Copy link
Contributor Author

noamr commented Mar 16, 2022

This looks really solid. This would result in reporting twice, right? Is that a case we might want to adjust to not do that or is it fine?

I wrote a WPT for this - apparently Chrome reports twice and Firefox/Safari reports once. I wonder if it's necessary to report twice or we can leave this optional.

@annevk
Copy link
Member

annevk commented Mar 17, 2022

@noamr I guess we could make it conditional upon preloaded response candidate, but I think what Chrome does is reasonable. You might also get slightly different failures which could be interesting to know about. Let's file a bug against Safari? Firefox's behavior is likely due to it not enforcing policies at all.

I pushed a smallish fixup commit that also changes the variable name from req to request. I think that ended up being wrong in the original PR due to the text moving around. Could you confirm it's now correct?

@noamr
Copy link
Contributor Author

noamr commented Mar 17, 2022

@noamr I guess we could make it conditional upon preloaded response candidate, but I think what Chrome does is reasonable. You might also get slightly different failures which could be interesting to know about. Let's file a bug against Safari? Firefox's behavior is likely due to it not enforcing policies at all.

SG, posted a WebKit bug and we can merge the WPT alongside the PR AFAIC

@annevk annevk merged commit 92b3578 into whatwg:main Mar 17, 2022
@noamr noamr deleted the preload-csp branch March 17, 2022 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Define behavior of preload when CSP was changed between fetching and consuming
2 participants