Peter Michaux wrote:
> [...] Thomas 'PointedEars' Lahn [...] wrote:
>> Peter Michaux wrote:
>>> If your site is foo.com and the other is bar.net then you can play a
>>> trick...
>>> Set up the domain name servers so that bar.foo.com points to bar.net
>>> Then in your JavaScript write
>>> document.domain = 'foo.com';
>>> Now you can make Ajax requests to both foo.com and bar.foo.com. It's
>>> just like you can make requests to foo.com and bar.net.
>>> This works around the XMLHttpRequest "same origin policy".
>> It doesn't. This works for DOM Level 0 objects only.
>
> What do you mean?
The Same Origin Policy was introduced with DOM Level 0 objects where
properties could be tainted; some properties were tainted and others were
not. The tainting was dropped later but the policy and affected properties
remained. Setting `document.domain' therefore was and is a way to work
around the SOP for those objects if there is the same second-level domain
(as you described).
http://docs.sun.com/source/816-6409-10/sec.htm#1021266
However, that does not work for XHR (as that is not part of DOM Level 0),
and that, at least partly, is good so.
http://web.archive.org/web/200504041...viour#security
http://www.mozilla.org/projects/secu...nts/jssec.html
This can be tested easily. Execute the following in the context of
<http://www.google.com/>:
try
{
document.domain = "google.com";
var x = new XMLHttpRequest();
x.open("GET", "http://groups.google.com/", false);
x.send(null);
window.alert(x.responseText);
}
catch (e)
{
// "Permission denied to call method XMLHttpRequest.open"
// even though document.domain was set
window.alert(e);
}
Tested with Firebug 1.05 on Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
It might be that some UAs work differently (although IE 6+7 and Opera 9.23
behaved much the same in my tests), however that would be a security issue
that would be fixed soon.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>