by olingern on 1/3/22, 3:54 AM with 243 comments
by igammarays on 1/3/22, 2:40 PM
by toomim on 1/3/22, 6:12 AM
I have hope that we can remove it, though, in new versions of HTTP.
CORS only exists because XMLHTTPRequest broke the assumptions of web 1.0 servers. Suddenly any web browser loading any page anywhere could make a request to your server without the user's explicit permission, and a ton of web servers had already been built and were running under the assumption that users would only hit their endpoints by explicitly typing in a URL or clicking on a link.
But each time we design a new version of HTTP, we get an opportunity to remove CORS restrictions for it, because there aren't any servers running the new version yet.
And with Braid (https://braid.org), we're making changes that are big enough that I think it really warrants taking a fresh look at all of this stuff. So I have hope that we can eliminate CORS and all this ugliness.
by herpderperator on 1/3/22, 7:41 AM
But don't worry! AWS thought of this! They invented Another Cloud Thing, namely Lambda@Edge, to solve this. Now you can run a JS function for every single request that hits your CloudFront Distribution so that you can run logic in there to strip the prefix before it gets passed to your origin. You read that right! Execute code every time a request hits your proxy! But wait, doesn't executing code for every single request sound insane AND doesn't it also add latency which this was trying to remove? Yes! Isn't cloud just lovely?
by Ralo on 1/3/22, 8:21 AM
Using Emscripten and threads, you require COOP & COEP headers to be sent via the main document. This is not common practice for static html hosting sites, thus requiring that you have access to a config file or .htaccess, and requires ALL assets to be hosted exclusively on that same server.
Killing my project is a bit extreme, but killed my motivation.
It's a web-based game with multiplayer that I was hoping people would modify and expand on, hosting themselves, uploading to places like Github.
I've recently started modifying Emscripten's runtime library to try and treat each webworker as a separate instance that just communicates between each other. This has major overhead as each thread is a new memory instance. I've tried getting it to extract each function into it's own module for a webworker to load but that's a major task.
Web apps want to act as desktop applications but they're so held back by security it's nearly impossible. We don't even have a proper local storage system.
To quote Dilbert, "Security is more important than usability. In a perfect world, no one would be able to use anything."
by miyuru on 1/3/22, 5:45 AM
Is it to point requests to sub path of the main domain to reduce OPTIONS requests? eg: api.example.com ---> example.com/api
In that case why not use proper "Access-Control-Max-Age" headers?
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Ac...
by mrweasel on 1/3/22, 11:17 AM
Instead, we now have a reverse proxy (haproxy) that "fixes" the missing CORS headers, by intercepting the OPTIONS call and return a dummy response with the correct headers included. The developer basically understand NOTHING in regards to CORS, so whenever the silly SPA breaks, the logic is always the same: "CORS is broken, fix it". At not point has it been an option to fix the API service to include the correct headers.
We could just have moved the API to /api and saved days of debugging and writing work-arounds, but no, api.customersite.com looks more professional.
by weitzj on 1/3/22, 7:53 AM
Then of course you don’t need CORS
by malft on 1/3/22, 6:37 AM
(You can even do POSTs without preflight if you use a whitelisted content-type.)
by willseth on 1/3/22, 4:03 PM
by eins1234 on 1/3/22, 6:18 AM
I remember taking a look at this a while ago and only found ways to do this through workers, so was turned off by the potential cost scaling. Ended up just setting a high `Access-Control-Max-Age` and calling it a day. But maybe I've missed a more cost effective way to accomplish this?
by kzemek on 1/3/22, 8:27 AM
by ManuelKiessling on 1/3/22, 8:07 AM
The resulting architecture does not require any CORS requests, too:
https://manuel.kiessling.net/2021/05/02/tutorial-react-singl...
by vfistri2 on 1/3/22, 1:27 PM
On a side note at previous company I've worked at, speed was critical, so we were forced to do same tactic, use /api instead of api.domain.com which resulted in huge improvements :)
by colinclerk on 1/3/22, 7:02 AM
by noduerme on 1/3/22, 11:20 AM
Context here: I'm maintaining a PWA that has to run on local iphones/android devices and maintain contact with a server on local networks in the 127.x block. But the point of download for the app itself is under an https domain on the open internet. It uses an iframe to check lots of local 127.x.x addresses until it finds one with a local server, and bootstraps itself to the code on the local server that way; unfortunately, it can't run as a true PWA because the iframe at the center of it violates CORS (due to the ban on mixing clear and SSL requests in the more recent versions of Chrome and Safari). Would be nice if the local servers could simply serve up their content and control the window without a whole domain-specific postMessage protocol.
by adamddev1 on 1/3/22, 9:42 AM
by SergeAx on 1/3/22, 10:13 AM
by nesarkvechnep on 1/3/22, 7:35 AM
by three14 on 1/3/22, 3:06 PM
- Set the Content-Type to "text/plain; charset=dropbox-cors-hack" instead of "application/json" or "application/octet-stream". [0]
...which is allowed in a "Simple" request that doesn't require a separate round trip for OPTIONS.
[0] - https://www.dropbox.com/developers/documentation/http/docume...
by donatj on 1/3/22, 7:42 AM
I'm guessing not, but if there was, theoretically could you just include your API response in the CORS rejection response?
by zemnmez on 1/3/22, 9:14 AM
by ngrilly on 1/3/22, 11:33 AM
by zagrebian on 1/3/22, 8:13 AM
* `Sec-Fetch-Site: cross-site` can be `Sec-Fetch-Mode: no-cors`
* `Sec-Fetch-Site: same-origin` can be `Sec-Fetch-Mode: cors`
It looks like all four combinations of these two headers are possible.
by dinkleberg on 1/3/22, 1:07 PM
by r_singh on 1/3/22, 5:59 AM
by crazypython on 1/3/22, 10:47 AM
by wdb on 1/3/22, 8:02 AM
by cwilby on 1/3/22, 8:50 AM
by avereveard on 1/3/22, 7:40 AM
by geuis on 1/3/22, 6:43 AM
…if you’re using a proxy like Cloudflare.
The short version of this post is that if your api is hidden behind Cloudflare, you can have it proxy requests to you api that lives on a subdomain.