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

COEP HTTP - works with CORS and CORP - but separately #37343

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hamishwillee
Copy link
Collaborator

@hamishwillee hamishwillee commented Dec 23, 2024

Fixes #36503

In addition this is a significant rework of the COEP header because I found it confusing.
The main problem I have with the existing doc is that it mixes up the effects and "nature" of CORS and CORP and the effect of this header when using these two.

Using the example of an <img> it is important to remember that a cross-origin fetch is allowed by default - if your HTML doesn't include crossorigin attribute the image is fetched in no-cors mode and will be returned by default and included unless the resource has CORP set on it.
However if you set the crossorigin attribute the request is not-no-cors - it might be a cors mode request and could have different settings for things like whether credentials are included.

So it isn't just you must set CORs or CORP, it depends on how you make the request. I have tried to draw that distinction.

PS. The bug was about navigation requests. I dont think they are relevant, because a navigation is not embedding a resource. Though I guess the fetch of a new content for a frame would count, and that would be handled as per usual for CORs (whatever that is).

@github-actions github-actions bot added Content:HTTP HTTP docs size/s [PR only] 6-50 LoC changed labels Dec 23, 2024
@@ -31,12 +31,24 @@ Cross-Origin-Embedder-Policy: unsafe-none | require-corp | credentialless
### Directives

- `unsafe-none`
- : This is the default value. Allows the document to fetch cross-origin resources without giving explicit permission through the CORS protocol or the {{HTTPHeader("Cross-Origin-Resource-Policy")}} header.
- : Allows the document to load cross-origin resources without giving explicit permission through the CORS protocol or the {{HTTPHeader("Cross-Origin-Resource-Policy")}} header.
Copy link
Collaborator Author

@hamishwillee hamishwillee Dec 23, 2024

Choose a reason for hiding this comment

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

What if CORP is same-origin - i.e. the unsafe-none would allow loading if CORP isn't set, but will the browser allow this if CORP explicitly says it does NOT want to be loaded?

I'm having trouble working it out from the spec.

Copy link
Contributor

Comment on lines +47 to +48
- : A document can load cross-origin resources that are requested in [`no-cors` mode](/en-US/docs/Web/API/Request/mode) **without** an explicit permission via the {{HTTPHeader("Cross-Origin-Resource-Policy")}} header.
In this case requests are sent without credentials: cookies are omitted in the request, and ignored in the response.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Again, what if CORP is same-origin - i.e. the unsafe-none would allow loading if CORP isn't set, but will the browser allow this if CORP explicitly says it does NOT want to be loaded?

If you enable COEP using `require-corp` and have a cross origin resource that needs to be loaded, it needs to support [CORS](/en-US/docs/Web/HTTP/CORS) and you need to explicitly mark the resource as loadable from another origin to avoid blockage from COEP. For example, you can use the [`crossorigin`](/en-US/docs/Web/HTML/Attributes/crossorigin) attribute for this image from a third-party site:
If you enable COEP using `require-corp` and want to embed a cross origin resource that supports [CORS](/en-US/docs/Web/HTTP/CORS), you will need to explicitly specify the HTML [`crossorigin`](/en-US/docs/Web/HTML/Attributes/crossorigin) attribute so that it is requested in `cors` mode.

For example, you would you this approach to fetch an image from a third-party site that supports CORS:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note, we could do with an equivalent example for CORP.

@hamishwillee hamishwillee marked this pull request as ready for review December 23, 2024 05:37
@hamishwillee hamishwillee requested a review from a team as a code owner December 23, 2024 05:37
@hamishwillee hamishwillee requested review from bsmth, a team and wbamberg and removed request for a team and bsmth December 23, 2024 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTTP HTTP docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

credentialless - explanation of "navigate" requests requiring Cross-Origin-Resource-Policy response header
1 participant