title: Why the cross-domain Ajax is a security concern?
body: <p>Why was it decided that using <strong>XMLHTTPRequest</strong> for doing XML calls should not do calls across the domain boundary?  You can retrieve JavaScript, images, CSS, iframes, and just about any other content I can think of from other domains. Why are the Ajax HTTP requests not allowed to cross the domain boundaries?  It seems like an odd limitation to put, considering the only way I could see it being abused, would be if someone were to inject Javascript into the page.  However, in this case, you could simply add an img, script, or iframe element to the document to get it to request the third party URL and send it to the server.  </p>
  
  <p>[Edit] </p>
  
  <p>Some of the answers point out the following reasons, let's point out the reasons they don't  create a major reason to disallow this.</p>
  
  <h2>XSRF (Cross Site Request Forgery, also known as CSRF, XSRF)</h2>
  
  <p>Your can do XSRF attacks without using this at all.  As a general rule, XMLHTTPRequest isn't used at all, simply because it's so hard to make an XMLHTTPRequest in a way that's compatible with all major browsers.  It's much easier to just add an img tag to the URL if you want them to load your URL.</p>
  
  <h2>Posting to third party site</h2>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    $.post("http://some-bank.com/transfer-money.php", 
           { amount: "10000", to_account: "xxxx" })
  &lt;/script&gt;
  </code></pre>
  
  <p>Could be accomplished with</p>
  
  <pre><code>&lt;body onload="document.getElementById('InvisbleForm').submit()"
      &lt;div style="display:none"&gt;
          &lt;form id="InvisbleForm" action="http://some-bank.com/transfer-money.php" method="POST"&gt;
              &lt;input type="hidden" name="amount" value="10000"&gt;
              &lt;input type="hidden" name="to_account" value="xxxxx"&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <h2>JPunyon: why would you leave the vulnerability in a new feature</h2>
  
  <p>You aren't creating any more insecurities.  You are just inconveniencing developers who want to use it in a way for good.  Anybody who wants to use this feature for evil (aka awesome) could just use some other method of doing it.</p>
  
  <h2>Conclusion</h2>
  
  <p>I'm marking the answer from <strong>bobince</strong> as correct because he pointed out the critical problem.  Because XMLHTTPRequest allows you to post, with credentials (cookies) to the destination site, and read the data sent back from the site, along with sending the persons credentials, you could orchestrate some javascript that would submit a series of forms, including confirmation forms, complete with any random keys generated that were put in place to try to prevent a XSRF.  In this way, you could browse through the target site, like a bank, and the bank's webserver would be unable to tell that it wasn't just a regular user submitting all these forms.</p>