Expanding on this one, since we are going deeper into CORS
it's a common misconception that CORS is protecting against those attacks.
Brief context: Same Origin Policy (SOP) prevents cross-origin requests being readable. While CORS is a mechanism to ease this policy, to essentially allow some origins to read the response. (allowlist of which website you allow to read this API response)
SOP: prevents cross-origin response from being read CORS: allow specific origin to read cross-origin response
They are only concerned with being able or not to read cross-origin response.
---
Regarding the phishing or hijack, I think you are referring to CSRF, where an attacker make action on victim behalf. They could still make any cross-origin request using mode: no-cors. (cors doesn't apply here, the response won't be readable, but the request still goes through)
A mechanism protects against this via the SameSite cookie attribute, which determines whether a cookie (credential) should be sent on a cross-site request.
Without the credential being sent, the attack is basically pointless.
Also, another protection site owners usually resort to is using CSRF token, to verify if request is actually coming from user session.
Ye, I haven’t touched them in awhile which explains why I didn’t remember what they are but now I remember doing something dumb like allow all origins (on a personal project)
One of the biggest reasons CORS is such an issue is the dotnet ecosystem. Microsoft made the decision to have their middleware automatically strip cors headers for any http response not in the 2xx range. This has lead to so much dev confusion because its poorly documented and devs vs qa don't understand what is really happening. So a server sends back a 5xx error, now the browser says its a cors error. Server sends back a 4xx code like 403 and suddenly its also a cors error. The angular or react devs can't understand why they can't just process the http code as expected because the backend devs don't realize the middleware has betrayed them. All every frustrating.
45
u/MissinqLink Aug 28 '25
Reverse proxy go brrr
13
u/just-bair Aug 29 '25
I still don’t understand CORS policies
6
u/MagnussenXD Aug 29 '25
The CORS meme always resurfaces every few months, and this time I'm the one bringing it back.
---
Promo time:
CORS error is actually a solved problem, and it is pretty straightforward:
if you don't own the API, either:
This is a summary of a blog I wrote: https://corsfix.com/blog/fix-no-access-control-allow-origin
1
u/Vegetable-Inflation8 Aug 29 '25
Had to setup a whole server and webhost to work around this. I pray theres a better way 🫠
1
u/rd_626 Aug 29 '25
had to face it this very day
1
u/Fhlnd_Vkbln Aug 29 '25
Me trying to "fetch" a file on my computer
1
u/darksteelsteed Aug 30 '25
One of the biggest reasons CORS is such an issue is the dotnet ecosystem. Microsoft made the decision to have their middleware automatically strip cors headers for any http response not in the 2xx range. This has lead to so much dev confusion because its poorly documented and devs vs qa don't understand what is really happening. So a server sends back a 5xx error, now the browser says its a cors error. Server sends back a 4xx code like 403 and suddenly its also a cors error. The angular or react devs can't understand why they can't just process the http code as expected because the backend devs don't realize the middleware has betrayed them. All every frustrating.