I have a problem with an OPTIONS methods request to an origin server that is protected by a Cloudflare access policy.
The curl for the request is equivalent to:
curl 'https://foo.acme.io/api/engine/engine/default/user' \
-X 'OPTIONS' \
-H 'authority: foo.acme.io' \
-H 'accept: application/json, text/plain, */*' \
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36' \
-H 'x-xsrf-token: {elided}' \
-H 'origin: https://foo.acme.io' \
-H 'sec-fetch-site: same-origin' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-dest: empty' \
-H 'referer: https://foo.acme.io/app/admin/default/' \
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
-H 'cookie: JSESSIONID={elided|; XSRF-TOKEN={elided}; __cfduid={elided}; _hp2_id.2360180481={elided}; {elided}={elided}; CF_Authorization={elided}' \
--compressed
Various tokens have been elided for security reasons but the token names have been preserved to indicate that they are present.
The following HTTP response is generated:
HTTP/2 403
date: Mon, 14 Dec 2020 00:59:44 GMT
cf-request-id: 07005bc11e0000fd4ab493b000000001
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=dH2wNpsXeCRGo53%2Bqj57tXiCMWhBGJE6bH6sBtxJFSgKA0WxCvO75YmYbrD4mqsNyAQjIpcH9p5xLbq4aATjHCoNyVJ19S36Yt0VZ8jy2z6z"}],"group":"cf-nel","max_age":604800}
nel: {"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
strict-transport-security: max-age=15552000
server: cloudflare
cf-ray: 6013fbe1c941fd4a-SYD
If I replace the OPTIONS method by GET the request succeeds, as expected, indicating that the cookies themselves are valid. There is no trace of the request in the origin server and this is not a cross-origin request. If I add an ALLOW or BYPASS rule to the firewall for requests using the OPTIONS method I see the requests pass through the firewall, but they are still rejected (somewhere, in Cloudflare, with a 403).
All the CORS options in the access policy are at their defaults (e.g. unconfigured).
If this was a cross-origin request, I would understand that may be some additional CORS configuration would be required, but this is not the case in this particular case.
I have read all the troubleshooting material here - https://developers.cloudflare.com/access/faq and searched the forums but I haven’t found anything that explains why an OPTIONS request is generating a 403 in this case.
Can someone explain what it is about Cloudflare’s handling of OPTIONS method requests I am not understanding and/or how I diagnose what is going wrong and/or fix it?