r/webdev • • Feb 20 '18

Understanding CORS

https://medium.com/@baphemot/understanding-cors-18ad6b478e2b
33 Upvotes

4 comments sorted by

2

u/[deleted] Feb 20 '18

What is CORS protecting if 'attackers that plant scripts on various websites' could just point those scripts to a proxy like mentioned in the article?

Why was CORS data not baked into the original page request and enforced on all sub resources instead?

7

u/flipperdeflip Feb 20 '18

Because of the cookies that get included when the evil script would call the protected api (assuming you were logged into that). A proxy on another domain would not get those cookies.

1

u/[deleted] Feb 20 '18

Thanks.

So, it is safe to open up CORS to allow * if you are designing an API that does not use cookies to auth (and want it to be consumed by external UIs)? As third party scripts will not be able to get access to the tokens in localstorage? So it is basically protecting against the browsers automatic handling of cookies?

1

u/flipperdeflip Feb 20 '18

Yes, the problem is the automatic cookies. If your API needs to be called from JS on any domain you can use *.