2012-12-02 40 views
2

我创建第三方的cookie <img src="http://example.com/test.php" />第三方cookie的 - 从其他域

test.php的阅读:

if($_GET['r']) { 
    header('Content-type: image/gif'); 
    // echo transparent 1x1 pixel 
    exit; 
} else { 
    setcookie('name', md5(time()), time()+60*60*24*30, '/'); 
    $url = 'http://example.com/test.php?r=1'; 
    header('Location: '.$url); 
    exit; 
} 

此代码创建第三方的Cookie。是否有任何方法通过JavaScript从不同于example.com的域中读取创建的cookie?

回答

2

否。JavaScript只能访问当前文档的Cookie,而不是其任何依赖项。

如果情况并非如此,那么作者可以从任何您可能拥有账户的网站加载图片,使用JavaScript读取cookie,将Ajax加载到其服务器,然后获取当前登录令牌的副本该网站。这将是一个巨大的安全漏洞。