最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Security concerns about CORS - Stack Overflow

programmeradmin1浏览0评论

I've just learned about CORS, basically because I didn't need it until now.

I've read that CORS enables cross-site origin, by sending HTTP headers with the AJAX call, so the other server can evaluate the request is ing from an approved site.

Now my main concern is, can't the HTTP headers be spoofed? For example, can't an attacker curl a request to the other server, sending the exact HTTP headers that my CORS request does? In that case, the server will accept the request, and the attacker will retrieve any sensitive data the server will send him.

We all know how easy it is to retrieve javascript from a page, so everything I send with CORS can easilly be seen by keen eyes. HTTP headers included.

So, I guess sensitive information should never be shared within a CORS munication... Or did I get this everything wrong? Please shed some light! :) Thanks

I've just learned about CORS, basically because I didn't need it until now.

I've read that CORS enables cross-site origin, by sending HTTP headers with the AJAX call, so the other server can evaluate the request is ing from an approved site.

Now my main concern is, can't the HTTP headers be spoofed? For example, can't an attacker curl a request to the other server, sending the exact HTTP headers that my CORS request does? In that case, the server will accept the request, and the attacker will retrieve any sensitive data the server will send him.

We all know how easy it is to retrieve javascript from a page, so everything I send with CORS can easilly be seen by keen eyes. HTTP headers included.

So, I guess sensitive information should never be shared within a CORS munication... Or did I get this everything wrong? Please shed some light! :) Thanks

Share Improve this question asked Jan 31, 2014 at 12:55 Chris MichaelidesChris Michaelides 7707 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Now my main concern is, can't the HTTP headers be spoofed? For example, can't an attacker curl a request to the other server, sending the exact HTTP headers that my CORS request does?

You have two misconceptions here.

  1. CORS headers are sent by the server not the client (although sometimes a client will make a pre-flight OPTIONS request)
  2. What the Same Origin Policy is defending against

The Same Origin Policy exists to stop Mallory's (evil) website from getting data from Bob's website by asking Alice's browser to request it when Alice visits Mallory's website.

If that was possible, then Mallory could get any information that was supposed to be a shared secret between Alice and Bob (such as Alice's account balance on Bob's banking website).

can't an attacker curl a request to the other server, sending the exact HTTP headers that my CORS request does?

Since Mallory has no way of knowing what security credentials need to be included in the request (because, for instance, they are stored in Alice's cookies for Bob's website): No.

But CORS doesn't matter here, but the Same Origin Policy isn't implemented by cURL since it isn't a browser running JavaScript supplied by arbitrary websites.

I guess sensitive information should never be shared within a CORS munication

It depends on the nature of the information.

If Alice and whatever websites you authorise in the CORS headers are allowed to see it, then it is fine to send it (although you should probably use SSL): So long as you have authenticated Alice's identity.

If only Alice and you site should see it, then don't put CORS headers on it (and don't provide any other way to bypass the Same Origin Policy, such as JSON-P).

If Alice shouldn't see it, then you should never send it to Alice's browser, CORS or no CORS.

发布评论

评论列表(0)

  1. 暂无评论