简体   繁体   English

同源策略与CORS的有用性

[英]Usefulness of Same Origin Policy with CORS

I have read some articles on Same Origin Policy and CORS and still doesn't understand well the security that it brings to the user. 我已经阅读了一些关于同源策略和CORS的文章,但仍然不能很好地理解它给用户带来的安全性。

The Same Origin Policy gives a true valuable security, preventing a site from an origin from accessing some webpage content on another website. 同源策略提供真正有价值的安全性,防止来自原点的站点访问另一个网站上的某些网页内容。 Thus preventing the threat of having the content of a iframe accessed by the script of the container, possibly faked/phishing website. 从而防止了容器脚本访问iframe内容的威胁,可能是伪造/网络钓鱼网站。

But here comes AJAX and CORS. 但这里有AJAX和CORS。 CORS gives the ability for the server to control which origins can access it. CORS使服务器能够控制哪些来源可以访问它。 But, at the end, it is the browser which stops the request if not allowed, after headers handcheck. 但是,最后,在标题手工检查之后,如果不允许,则是停止请求的浏览器。

So, imagine you get some malicious website myphishing.com . 所以,想象你得到一些恶意网站myphishing.com You want to show information from another trusted website mybank.com through AJAX request to this site. 您希望通过AJAX请求向本网站显示来自其他受信任网站mybank.com的信息。 This one is protected by well configured CORS headers only allowing request from mybank.com origin. 这个受到良好配置的CORS标头的保护,只允许来自mybank.com的请求。 What if, me author of myphising.com , relay all requests to mybank.com by a proxy that alter headers in both request and response way to fake client browser and bank server? 如果我是myphising.com的作者,通过代理向mybank.com转发所有请求, 以便在假请客户端浏览器和银行服务器的请求和响应方式中改变标头,该怎么办? It seems one can change the origin header in the request for a mybank.com one, and change the CORS response headers to make the browser think myphishing.com is allowed to make the request. 似乎可以在mybank.com请求中更改原始标头,并更改CORS响应标头以使浏览器认为myphishing.com可以发出请求。 Headers handcheck passed, you can then send the request and get the response with similar headers substitution tricks. 通过Headers handcheck,您可以发送请求并获得具有类似标头替换技巧的响应。

Perhaps I'm totally misleaded, but I would be very pleased if someone could show me where I have misunderstand the whole thing. 也许我完全被误导了,但如果有人能告诉我我误解了整件事情,我会很高兴。

Possible duplicate but I didn't find my answer here: What is the threat model for the same origin policy? 可能重复,但我在这里找不到答案: 同一起源政策的威胁模型是什么? .

What if, me author of myphising.com, relay all requests to mybank.com by a proxy that alter headers in both request and response way to fake client browser and bank server? 如果我是myphising.com的作者,通过代理向mybank.com转发所有请求,以便在假请客户端浏览器和银行服务器的请求和响应方式中改变标头,该怎么办?

You could do that anyway, CORS or no CORS. 无论如何你可以这样做,CORS或没有CORS。

If the request is coming from your proxy, however, then it has no way to know what credentials the browser would have sent to the server if the request was coming from the browser. 但是,如果请求来自您的代理,那么如果请求来自浏览器,则无法知道浏览器将向服务器发送的凭据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM