Reflect that GET, HEAD, and POST are always allowed methods #37266
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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