Top
Best
New

Posted by toilet 13 hours ago

Developers don't understand CORS (2019)(fosterelli.co)
267 points | 199 commentspage 4
robertclaus 11 hours ago|
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.
ivanjermakov 6 hours ago||
Sometimes it's a good thing when I try to use someone else's backend in my web app. For example map tile server or route builder, which are session-less and have no authentication.

The idea that HTTP servers are restricted to requests from a single domain by default is strange, wonder if CORS world be better off opt-in rather than opt-out.

kaoD 5 hours ago||
> wonder if CORS world be better off opt-in rather than opt-out.

It's necessary that the defaults are secure. More so, not less, if the problem is hard.

ChadNauseam 10 hours ago||
That describes pretty much every server I've ever written lol.
foundart 9 hours ago||
Correct. Where are some good explanations?
ottoflux 9 hours ago||
the amount of code i've seen either allowing * when it shouldn't because someone was desperately trying to make their code work is astounding.

contractors, "specialists", etc. who never took the time to read how CORS works and how simply you can handle a list of allowable sites, etc.

it's only complicated until you take the 5-10 minutes to properly understand what happens where. if you don't know, go do it now.

bornfreddy 9 hours ago||
5-10 minutes? I'm sold. Any link you can share?

I'm saying this as someone who has learned about CORS protections many times, implemented the solutions with care they deserved, but forgot most of it soon after - each time. So I'd be very happy to invest even 15 minutes to break this cycle.

oofbey 9 hours ago||
As somebody who has spent a lot more than 10 minutes trying to figure out why CORS was blocking what seemed legitimate, I sympathize with people doing the wrong thing, and disagree with your assertion that it’s not that complicated. Maybe I’m just slow. But objectively I know I’m not.
N_Lens 9 hours ago||
“Objectively”
threethirtytwo 4 hours ago||
AI understands CORs. So that's something AI does better than developers.
rusk 7 hours ago||
It’s TOS for using ebdpoint. It says:

access is provided under condition you respect these restrictions

You are not obliged to honour this. It is not enforceable so it seems strange.

Browsers enforce it, but it can be turned off and nobody expects it to be implemented by a simple REST client application.

It’s a gentleman’s agreement. It’s a statement of expectation to the browser. On the one hand it may be for the protection of the browser user, from cross site attacks, and from malicious code on the web.

But crucially it provides little protection for the endpoints themselves bar accidental misuse.

It is very unusual and rare example of “cooperative” security in a web that’s frequently so adversarial.

And that’s what makes it hard to grasp.

9dev 6 hours ago|
> Browsers enforce it, but it can be turned off and nobody expects it to be implemented by a simple REST client application.

No, you're missing the point. Normal people using normal browsers with default settings have CORS enabled. That's the vast majority of your users; everyone who disables it stupidly opts into a risk themselves without any reason to.

So the expectation that CORS is enabled on your user's devices holds. This means it's not a gentleman's agreement!

d--b 7 hours ago||
A CORS protected endpoint tells YOUR BROWSER not to let YOU access its content if the website you’re browsing from is not whitelisted.

It’s confusing because unlike most security features, it’s meant to protect the users from themselves. The risk comes from a combination of users being allowed to visit malevolent sites and browsers letting all websites do a lot of random stuff, including making 3rd party requests with cookies and private stuff

moring 5 hours ago||
> it’s meant to protect the users from themselves

This is false. It is meant to protect users from a confused-deputy attack made by malicious websites, where that website makes a request to a "serious" API but the user has never asked for, or approved, that request.

Blaming the user for everything that happens serves nobody.

user43928 7 hours ago|||
Isn't it arguably the opposite?

A CORS header in the response tells your browser to relax CORS restrictions.

IceDane 5 hours ago||
Like the sibling said: CORS is the relaxation of default security features. It's even in the name: Cross-Origin Resource Sharing.
koolala 5 hours ago||
'No Sharing' is a policy on sharing. Being literal about the name misses their point.
dboreham 11 hours ago||
The only thing to understand is that it does nothing useful today.
kristiandupont 6 hours ago||
What do you mean? It's a way to mitigate a certain attack vector and as far as I can tell, it works as intended given the circumstances it was designed under.
paulryanrogers 11 hours ago||
Doesn't it help protect clients from malicious 3P JS?

At least so long as they don't have malicious extensions or a non-CORS browser?

lofaszvanitt 4 hours ago||
Because they don't like reading docs. At the same time it is an overcomplicated fucking mess, just like CSP headers just like css syntax/wording. Somehow everything that is security related is overly complex.... it's a miracle!
ralusek 7 hours ago||
I understand CORS and I don't.

TL;DR: It's a restriction your browser gives itself. If it's on Domain A and it sees a request going out to Domain B, unless Domain B responds saying that it's expecting traffic from Domain A, the browser prevents itself from making the call.

I think the part about it that is off/silly to most people is that it's not a normal security threat model, because a malicious client could simply just...not impose that restriction on itself. You're perfectly capable of going and curling that same request to that backend, or calling it from an app, or any number of other things. So it's not really protecting your protected resource, the backend, from malicious clients.

All of that is where I feel like I understand clearly. The part I fail to retain is the exact scenarios it does protect against, which IIRC, are basically about attempting to protect your users from being misguided on other clients that are acting as your client, something like that (but again, this literally only applies to browsers). It's just kind of a weird niche problem that I often find myself thinking "I mean why is the user on another client and have allowed themselves to authenticate on that client with my server...this sounds like the user's fault."

eurleif 6 hours ago||
The part you may be missing is that cookies exist.

User visits A.com, types in their username and password, and a cookie is set in their browser. The browser will send that cookie back to A.com with all subsequent requests, and A.com's server will use it to enable access to the user's account.

Now the user visits B.com, which makes a request to A.com/private_user_data. The user's cookie is sent with this request, so A.com will respond with (and B.com will receive) the user's private data without the user consenting to this at all (not even in a "misguided" way).

9dev 6 hours ago||
> […] the browser prevents itself from making the call.

That's not strictly correct, by the way. The request is made, but the JavaScript code on Domain A is not allowed to read the response. This matters when a request is destructive on its own, for example.

ralusek 6 minutes ago|||
My understanding was it was an OPTIONS preflight request that is made.
eurleif 6 hours ago|||
To go even deeper into the weeds: this is only true of "simple" requests[0]. Requests that aren't "simple" always require preflight approval. This is based on which requests a <form> or link could already create without approval; since the dawn of time, <form method="post"> could submit a potentially-destructive request, and sites needed to protect themselves against that via XSRF tokens; so CORS could allow submiting the same class of requests without preflight approval, and not introduce any new attacks. But there's no <form method="delete">, for example, so CORS would have created attacks against previously-secure sites if it had allowed DELETE requests without preflight approval.

[0] https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/COR...

sala0986 47 minutes ago|
[flagged]
More comments...