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

Reflect that GET, HEAD, and POST are always allowed methods #37266

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

hmolsen
Copy link
Contributor

@hmolsen hmolsen commented Dec 18, 2024

Description

I changed the example to be more meaningful using PUT and DELETE and added a short description to the directive.

Motivation

We recently came across the behaviour that even a non-simple POST request is allowed by the browsers, even if POST is not explicitely stated in the A-C-Allow-Methods header. So I looked it up in the specification and found that in fact all GET, HEAD, and POST requests are CORS-safelisted methods (see also fetch-spec https://fetch.spec.whatwg.org/#ref-for-cors-safelisted-method%E2%91%A2).

A google search revealed that I am not alone in being confused by this. This MDN page added to the confusion, as it shows an example allowing explicitely GET and POST by using this header, which does not make sense, as these HTTP methods are always allowed either way.

Additional details

Fetch Spec ("If request’s method is not in methods, request’s method is not a CORS-safelisted method, ..."
https://fetch.spec.whatwg.org/#ref-for-cors-safelisted-method%E2%91%A2

Confusion on the web:
dotnet/aspnetcore#40616
https://stackoverflow.com/questions/74596745/if-the-post-method-is-not-idempotent-and-is-not-a-safe-method-why-does-the-cors

Related issues and pull requests

We recently came across the behaviour that even a non-simple POST request is allowed by the browsers, even if POST is not explicitely stated in the A-C-Allow-Methods header. So I looked it up in the specification and found that in fact _all_ GET, HEAD, and POST requests are CORS-safelisted methods (see also fetch-spec https://fetch.spec.whatwg.org/#ref-for-cors-safelisted-method%E2%91%A2).

A google search revealed that I am not alone in being confused by this. This MDN page added to the confusion, as it shows an example allowing explicitely GET and POST by using this header, which does not make sense, as these HTTP methods are always allowed either way.

So I changed the example to be more meaningful and added a short description to the <method> directive.
@hmolsen hmolsen requested a review from a team as a code owner December 18, 2024 22:02
@hmolsen hmolsen requested review from hamishwillee and removed request for a team December 18, 2024 22:02
@github-actions github-actions bot added Content:HTTP HTTP docs size/xs [PR only] 0-5 LoC changed labels Dec 18, 2024
Copy link
Contributor

github-actions bot commented Dec 18, 2024

Preview URLs

External URLs (1)

URL: /en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
Title: Access-Control-Allow-Methods

(comment last updated: 2024-12-19 11:26:28)

@bsmth bsmth requested review from bsmth and removed request for hamishwillee December 19, 2024 11:14
Copy link
Member

@bsmth bsmth left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fix!

@bsmth bsmth merged commit c376662 into mdn:main Dec 19, 2024
8 checks passed
@hmolsen hmolsen deleted the patch-2 branch December 19, 2024 20:43
allan-bonadio pushed a commit to allan-bonadio/content that referenced this pull request Dec 25, 2024
a non-simple POST request is allowed by the browsers, even if POST is not explicitly stated in the A-C-Allow-Methods header. changed the example to be more meaningful and added a short description to the <method> directive.

Co-authored-by: Brian Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTTP HTTP docs size/xs [PR only] 0-5 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants