
Chrome 77 made a change that requires code 204 to be returned from preflight OPTIONS requests, rather than code 200 (otherwise results in long response times for some API requests). This change is reflected in a recent commit to the asm89/stack-cors project here: https://github.com/asm89/stack-cors/commit/a779b74d5719b8a752dbb5fa83453...
Drupal core has automated tests in tests/Drupal/FunctionalTests/HttpKernel/CorsIntegrationTest.php::CorsIntegrationTest but it is unclear if these tests check the preFlight response.
Once a new version of asm89/stack-cors is released, either:
- Update automated tests to handle the 204 response from CORS
- OR: Add a new test for the preflight response handling.
This could be a minor issue if existing tests are not affected. But is a change in asm89/stack-cors for core devs to be aware of.
Also posting this for people searching for why CORS is broken (results in long response times) in D8.x with the latest Chrome 77 version. Until there is an official release of asm89/stack-cors, we will likely be pointing to the specific commit hash in our composer.json
Comment | File | Size | Author |
---|---|---|---|
#2 | 3089999-1-asm89-cors-preflight-response-code.patch | 2.87 KB | mr.baileys |
Comments
Comment #2
mr.baileysThe test in
\Drupal\FunctionalTests\HttpKernel\CorsIntegrationTest
only covers CORS configuration and CORS responses to regular requests (GET and POST). It does not initiate a CORS preflight request. Quickly searching through all core tests, it doesn't look like we are doing preflight CORS requests anywhere in core, so the change in asm89/cors-stack should not cause any failures in our tests. Attached is a quick patch pinning asm89/stack-cors to the relevant commit to verify the claim that upgrading to the next version of asm89/stack-cors won't break anything.I was confused about why this change would cause long response times. Found the answer in Changes to Cross-Origin Requests in Chrome Extension Content Scripts:
... so essentially requests that do not pass CORS preflight request validation will just timeout.
Comment #9
quietone CreditAttribution: quietone at PreviousNext commented@mpotter, thanks for making reporting this and making a patch.
This is now outdated. asm89/stack-cors has been updated more than once since this was created. The latest was to^2.1 in Aug 2022 #3302755: On-the-fly JavaScript minification.
I am closing this as outdated.