What's the point of the Anti-Cross-Domain policy?

前端 未结 4 473
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 10:42

Why did the creators of the HTML DOM and/or Javascript decide to disallow cross-domain requests?

I can see some very small security benefits of disallowing it but in

相关标签:
4条回答
  • 2021-01-12 11:11

    To clarify some of the ideas in the questions into a specific use case..

    The cross domain policy is generally not there to protect you from yourself. Its to protect the users of your website from the other users of your website (XSS).

    Imagine you had a website that allowed people to enter any text they want, including javascript. Some malicious user decides to add some javascript to the "about yourself" field. Users of your website would navigate his profile and have this script executed on their browser. This script, since its being executed on your website's behalf, has access to cookies and such from your website.

    If the browser allowed for cross domain communication, this script could theoretically collect your info and then upload it to a server that the malicious user would own.

    0 讨论(0)
  • 2021-01-12 11:18

    The actual cross-domain issue is huge. Suppose SuperBank.com internally sends a request to http://www.superbank.com/transfer?amount=100&to=123456 to transfer $10,000 to account number 123456. If I can get you to my website, and you are logged in at SuperBank, all I have to do is send an AJAX request to SuperBank.com to move thousands of dollars from your account to mine.

    The reason JSON-P is acceptable is that it is pretty darn impossible for it to be abused. A website using JSON-P is pretty much declaring the data to be public information, since that format is too inconvenient to ever be used otherwise. But if it's unclear as to whether or not data is public information, the browser must assume that it is not.

    0 讨论(0)
  • 2021-01-12 11:27

    Here's a distinction for you: Cross-domain AJAX allows a malicious site to make your browser to things on its behalf, while JSON-P allows a malicious server to tamper with a single domain's pages (and to make the browser do things to that domain on your behalf) but (crucial bit) only if the page served went out of its way to load the malicious payload.

    So yes, JSON-P has some security implications, but they are strictly opt-in on the part of the website using them. Allowing general cross-domain AJAX opens up a much larger can of worms.

    0 讨论(0)
  • 2021-01-12 11:30

    When cross-domain scripting is allowed (or hacked by a clever Javascripter), a webpage can access data from another webpage. Example: joeblow.com could access your Gmail while you have mail.google.com open. joeblow.com could read your email, spam your contacts, spoof mail from you, delete your mail, or any number of bad things.

    0 讨论(0)
提交回复
热议问题