跨域js投递cookie测试

来源:互联网 发布:金属杆中性笔知乎 编辑:程序博客网 时间:2024/06/06 05:39

测试情况说明:

页面在 stg.a.com/test.htm

页面内容空


脚本在 stg.b.com/test.js

脚本情况

document.cookie="WT.test="+new Date().getTime()+"; path=/";
document.cookie="WT.a="+new Date().getTime()+"; path=/; domain=stg.a.com";
document.cookie="WT.b="+new Date().getTime()+"; path=/; domain=stg.b.com";
document.cookie="WT.c="+new Date().getTime()+"; path=/; domain=stg.c.com";
alert(document.cookie);



通过stg.a.com/test.htm访问文件,只能输出如下

WT.test=1422598902533; WT.a=1422598902534

而且在stg.b.com和stg.c.com域名都找不到投递的cookie


所以结论如下:

1. 无论js和页面是否同一域名,都可以读写页面下的cookie

2. 如果页面是域名A,js是域名B,那页面加载后js不能操作B域的cookie

3. C域名更不可能

0 0