| ▲ | Developers don't understand CORS (2019)(fosterelli.co) | |||||||||||||||||||||||||||||||
| 50 points by toilet 3 hours ago | 20 comments | ||||||||||||||||||||||||||||||||
| ▲ | stephbook 4 minutes ago | parent | next [-] | |||||||||||||||||||||||||||||||
I still don't understand the threat model and, obviously, it's not explained here either. I log in to social.net. I click on scam.org and change sites. I'm on scam.org and it triggers a request to social.net/friends. No cookies are sent, no JWT. I'm not logged in and get a "Needs login" HTTP error. Nothing bad happens. I thought that's how it works without CORS already. | ||||||||||||||||||||||||||||||||
| ▲ | encomiast an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
It's not just CORS that's hard to understand. Many (most?) developers don't really understand the threat model. And even when it's explained it hard to see why it's a big deal. Part of this is that backend developers usually have to configure CORS and it's not an access privilege protection. From the point of view of the backend it doesn't seem to matter. Bad guys can't get it. From the point of view of the front-end it's often seen as a nuisance. The article does a nice job giving a concrete example. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | piyh 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
The only thing I remember about CORS is that it takes way longer than expected to debug, by design the error messages sent to the browser are intentionally gutted, and CORS error scenarios are hard to tell from other failure modes atfirst glance. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | koolala 32 minutes ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
CORS sucks since Cross-Origin-Embedder-Policy: credentialless was never made standard across all browsers. It's a browser client restriction you can't turn off. If you want to do anything interesting with WWW content you have to run your own browser or run an out-of-box one off a proxy server that breaks everything. | ||||||||||||||||||||||||||||||||
| ▲ | jdw64 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Sometimes I'm not even sure what I truly 'understand.' When even senior engineers working on products used by hundreds of millions of people, like Zoom, have had these kinds of issues, it makes me wonder. So I usually just write code the way it was left by my seniors, out of inertia. But I realize that the area I work in is actually incredibly abstracted. | ||||||||||||||||||||||||||||||||
| ▲ | preommr an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Because, like many things in web, it's a patchwork of compromises due to legacy issues, rampant inconcistencies and trying to be too clever. You get results where it's really difficult intuitively understand it because at that point you're not really meant to. Realistically, people just follow a guide, or some lib, and move on. | ||||||||||||||||||||||||||||||||
| ▲ | frogulis an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
From my experience, the reason CORS is hard to understand is that it's somehow inverted from the default "shape" of security in web dev. We easily form the intuition of the client being a by-default untrusted entity, and checking whether it has the privilege of accessing this data, where the server is the arbiter of that access. CORS is so inherently different to that, and while the information is easily available, it requires a short but careful read to grok the idea -- which a dev tunnel-visioning towards getting their application code written may not wish to slow down for. | ||||||||||||||||||||||||||||||||
| ▲ | deathanatos 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Generally when I'm debugging these, I need/want to know what was the preflight (if applicable), and was the preflight what was expected? When I help others debug these, generally I find there is little expectation of what the preflight "should" be, and instead just a bunch of stochastic attempts to adjust the server's response headers to get the browser to capitulate — regardless of whether that makes any sense at all. I would also say I think Firefox's network inspector is better in this area. (But I'm often having to ask others to "no, don't send the failing request, send the CORS preflight", we need to understand what happened with it.) > Anecdotally, lots of developers I’ve talked with don’t understand well how CORS works. Yeah, most FE devs I've worked with seem to not understand CORS. > Is the CORS API too complex and confusing I think it can be hard if you don't understand why the exceptions to preflights are what they are, but the moment you internalize "because the browser can already emit that request in other cases" then it becomes obvious what categories are what & why. | ||||||||||||||||||||||||||||||||
| ▲ | robertclaus an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I bet there's an awful lot of servers out there that will happily take CORS requests from any host because someone didn't understand why their second domain couldn't talk to the same API. | ||||||||||||||||||||||||||||||||
| ▲ | iririririr an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
everything browser is about still allowing The Bad Thing Ad Companies need. cors et al is a freaking mess because those things are designed by a comitee choke full of people who last promotion was their cool idea about how to monetize referrer, or how do cookie match across domains, or profile you with millisecond it takes to list your usb audio devices, or etc etc etc | ||||||||||||||||||||||||||||||||
| ▲ | dboreham an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
The only thing to understand is that it does nothing useful today. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | mock-possum an hour ago | parent | prev [-] | |||||||||||||||||||||||||||||||
I honestly just can’t be arsed. I write the code to do the thing I want, and if CORS throws a wrench into things, I make Claude fix it for me. I’m tired boss. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||