CORS - Access apps and preflight issue

Preflight doesn’t contain the cookie necessary to authenticate, therefore Cloudflare responds 302 to login.

I don’t see any way around that, if I have two applications running under Access which need protected, but need to talk to each other’s api’s.

Do you have any plans to address the preflight (OPTIONS) issue?
Your server-side worker seems like a very capable solution. Perhaps by having a client-side worker to intercept the CORS request and attached the access token to a header value?

I was able to solve this myself by doing as mentioned.

A CF Worker script to process requests (ignoring preflight) for a token, then processing that token as to whether or not user has access to the site. And then a browser-level worker to attach a header for requests which are cross-origin, such that the server worker can determine auth status.
The reasoning behind that is that CORS requests by default are not withCredentials (‘include’ becomes ‘omit’). So cookies are not transferred, and cannot be transferred period.

This does require one to utilize: Asynchronous Access to HTTP Cookies - Chrome Developers for the service worker to handle it. You might be able to get around that with a header provisioned by your service or some sort of fancy cache system

I believe this could be much easier solved by CF staff for the provided [Access] service.
CORS preflight is step 1.
Cross origin (and even cross-“application” cf tokens for that matter) would be step 2.

CF server workers come with Mozilla crypto.subtle (hint: make your own token w/ pub/priv keys).
So I’ll leave the rest to he who reads.
Use: Sign requests · Cloudflare Workers docs
And: CORS header proxy · Cloudflare Workers docs
As boiler code to produce the desired result.

Does such a use case bypass Cloudflare access? Sorta. But not really (still is based upon requirement to login to Access). The only item getting through is preflight, which doesn’t contain anything in either direction anyway; other than a proof that the service exists.
But without CF staff providing the CORS feature as mentioned, there is no other way.


A year passed, are there simpler ways to achieve this now?

1 Like