@zmol: nice to know that you experimented at my request :) ( How to check if cross-domain requests are disabled )
Cross-domain policy says something like this:
your domain A serves page A, which has the ability to make ajax calls.
this "pageA" ajax can only request resources from domainA and possibly never from domainB.
in your words
if site1.com serves script.js, script.js can only upload and download content through site1.com and not through othersite.com.
on the other hand, if script.js was sent from othersite.com, it will not be able to call anything on site1.com because the server rejects the request due to this policy.
this is true for everyone, since you cannot call ajax on google and Google cannot ajax call your domain officially. [There are workarounds, but it is not now]
now some perplexities remain? :)
edit - I forgot to answer your question:
My goal is to protect ajax URLs so that they are not used by external sites such as APIs to dump data into my database.
Itβs not possible to βprotectβ ajax URLs, as others say, ajax calls are normal server requests, but they have an Origin header.
Origin header prompts the server to trust the caller or not :)
edit - I see that there are ways to protect, for example, preventing CSRF ... [I think this is only one possibility] Thanks @David Dorward for this. my +1
source share