This question is about protecting against Cross Site Request Forgery attacks only.
It is specifically about: Is protection via the Origin header (CORS) as good as the protection via a CSRF token?
Example:
- Alice is logged in (using a cookie) with her browser to "https://example.com". I assume, that she uses a modern browser.
- Alice visits "https://evil.com", and evil.com's client side code performs some kind of request to "https://example.com" (classic CSRF scenario).
So:
- If we don't check the Origin header (server-side), and no CSRF token, we have a CSRF security hole.
- If we check a CSRF token, we're safe (but it's a bit tedious).
- If we do check the Origin header, the request from evil.com's client side code should be blocked just as well as it would when using a CSRF token - except, if it is possible somehow for evil.com's code to set the Origin header.
I know, that this should not be possible with XHR (see e.g. Security for cross-origin resource sharing), at least not, if we trust the W3C spec to be implemented correctly in all modern browsers (can we?)
But what about other kinds of requests - e.g. form submit? Loading a script/img/... tag? Or any other way a page can use to (legally) create a request? Or maybe some known JS hack?
Note: I am not talking about
- native applications,
- manipulated browsers,
- cross site scripting bugs in example.com's page,
- ...
Origin
? That would negate CORS protection. – Paul Draper