Webkit的跨域安全问题说明
2011-09-13 22:17
771 查看
这里有个简单的测试页面: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{
//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). */ }
以下是小段测试代码(刻意修改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错误信息:
![](http://files.jb51.net/upload/201109/20110913221651133.png)
据了解,采用此类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!
您可能感兴趣的文章:
- jquery下利用jsonp跨域访问实现方法
- jquery下异步提交表单 异步跨域提交表单
- 基于Jquery的跨域传输数据(JSONP)
- Ajax跨域代理访问网络资源的实现代码
- 使用JSON实现数据的跨域传输的php代码
- jquery $.getJSON()跨域请求
- JS跨域总结
- js iframe跨域访问(同主域/非同主域)分别深入介绍
- 借助script进行Http跨域请求:JSONP实现原理及代码
- JQuery的Ajax跨域请求原理概述及实例
- UEditor 编辑器跨域上传解决方法
- AJAX的跨域访问-两种有效的解决方法介绍
- 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实现跨域通信例子
- 关于JavaScript跨域问题及实时刷新解决方案
- IE9版本以下ajax 跨域问题可行解决方法
- js跨域问题浅析及解决方法优缺点对比
- 使用jsonp完美解决跨域问题
- 5种处理js跨域问题方法汇总
- js同源策略详解
- 深入浅析同源策略和跨域访问
相关文章推荐
- Webkit的跨域安全问题说明
- flex 跨域访问 #2048: 安全沙箱冲突 问题解决方法
- 在Mac OS下开发html5+JS Chrome 浏览器 跨域 和 安全访问问题
- [解决]WebLogic跨域访问安全问题
- Chrome 浏览器跨域和安全访问问题 使用 chrome的命令行标记:disable-web-security 参数联调线上数据
- 跨域问题解决方案(HttpClient安全跨域 & jsonp跨域)
- 浅析浏览器的跨域安全问题
- Flex中跨域访问及#2048安全沙箱错误问题
- 父页面操作iframe子页面的安全漏洞及跨域限制问题
- Flash实现Websocket的跨域问题-安全沙箱问题解决办法
- Chrome 浏览器跨域和安全访问问题 使用 chrome的命令行标记:disable-web-security 参数联调线上数据
- 网站常见的安全问题说明
- 解决 在Mac OS下开发html5+JS Chrome 浏览器 跨域 和 安全访问问题
- webkit 相关的一些列安全问题
- Chrome 浏览器跨域和安全访问问题 使用 chrome的命令行标记:disable-web-security 参数联调线上数据
- 揭密鬼页 浅析浏览器跨域安全问题
- 解决 在Mac OS下开发html5+JS Chrome 浏览器 跨域 和 安全访问问题
- 使用 chrome的命令行标记:disable-web-security 参数联调线上数据----------Chrome 浏览器跨域和安全访问问题
- 跨域问题解决方案(HttpClient安全跨域 & jsonp跨域)
- 跨域问题解决方案(HttpClient安全跨域 & jsonp跨域)