信息发布→ 登录 注册 退出

Webkit的跨域安全问题说明

发布时间:2026-01-11

点击量:
这里有个简单的测试页面:IE、火狐弹出"hello world",而chrome,safari,opera毫无反应。
以下是小段测试代码(刻意修改domain,让父页面和子页面为不同域页面):
1.父页面代码:
复制代码 代码如下:
<script>
document.domain = "nunumick.me";
function doTest(){
alert('hello world');
}
</script>
<iframe src="http://www.nunumick.me/lab/x-domain/webkit-test.html">
</iframe>

2.子页面代码:
复制代码 代码如下:
<script>
try{
top.name;
}catch(e){
document.domain = 'nunumick.me';
top.doTest();
}
</script>

以上代码目的是尝试在访问异常时动态修改domain达到顺利访问,但webkit内核浏览器粗暴地报错而非抛出可截获的异常,其他浏览器均如期运行。

chrome错误信息:

据了解,采用此类try catch方式做安全可行性判断的并不只是个别现象,如DOJO

复制代码 代码如下:
try{
//see if we can access the iframe's location
//without a permission denied error
var iframeSearch = _getSegment(iframeLoc.href, "?");
//good, the iframe is same origin (no thrown exception)
if(document.title != docTitle){
//sync title of main window with title of iframe.
docTitle = this.iframe.document.title = document.title;
}
}catch(e){
//permission denied - server cannot be reached.
ifrOffline = true;
console.error("dojo.hash: Error adding history
entry. Server unreachable.");
}

再如FCKeditor
复制代码 代码如下:
try{
if ( (/fcksource=true/i).test( window.top.location.search ) )
sFile = 'fckeditor.original.html' ;
}
catch (e) { /* Ignore it. Much probably we are insi
de a FRAME where the "top" is in another domain (security error). */ }

还有很多网友的反馈:chrome bug report

以上代码在chrome,safari,opera均不适用。翻了一些资料,记录在此:
1.html5 security location
2.webkit dev lists
从webkit开发人员的讨论消息中看到,他们承认这个问题但并不情愿去改正,holly shit!

标签:# 报错  # IE9版本以下ajax 跨域问题可行解决方法  # js跨域问题浅析及解决方法优缺点对比  # 使用jsonp完美解决跨域问题  # 5种处理js跨域问题方法汇总  # js同源策略详解  # 深入浅析同源策略和跨域访问  # 有个  # 在此  # 这个问题  # 据了解  # 弹出  # 此类  # 火狐  # 关于JavaScript跨域问题及实时刷新解决方案  # 翻了  # 而非  # 错误信息  # 还有很多  # 开发人员  # 均不  # 抛出  # 小段  # 再如  # 目的是  # lab  # html  # AJAX的跨域访问-两种有效的解决方法介绍  # 跨域  # jquery下利用jsonp跨域访问实现方法  # jquery下异步提交表单 异步跨域提交表单  # 基于Jquery的跨域传输数据(JSONP)  # Ajax跨域代理访问网络资源的实现代码  # 使用JSON实现数据的跨域传输的php代码  # jquery $.getJSON()跨域请求  # JS跨域总结  # js iframe跨域访问(同主域/非同主域)分别深入介绍  # 借助script进行Http跨域请求:JSONP实现原理及代码  # JQuery的Ajax跨域请求原理概述及实例  # UEditor 编辑器跨域上传解决方法  # Webkit  # Ajax跨域查询完美解决通过$.getJSON()实现  # PHP如何利用P3P实现跨域  # 如何设置iframe高度自适应在跨域情况下的可用方法  # 完美解决AJAX跨域问题  # AJAX跨域请求json数据的实现方法  # 用iframe设置代理解决ajax跨域请求问题  # jquery ajax jsonp跨域调用实例代码  # jquery ajax跨域解决方法(json方式)  # jquery的ajax和getJson跨域获取json数据的实现方法  # 用jQuery与JSONP轻松解决跨域访问的问题  # php跨域cookie共享使用方法  # JavaScript使用HTML5的window.postMessage实现跨域通信例子  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!