最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Webkit的跨域安全問(wèn)題說(shuō)明

 更新時(shí)間:2011年09月13日 22:17:02   作者:  
在使用try catch處理iframe跨域產(chǎn)生的異常時(shí),chrome和safari瀏覽器似乎不能正常運(yùn)作:他們直接拋出了錯(cuò)誤而沒(méi)有拋出可供JS截獲的異常。
這里有個(gè)簡(jiǎn)單的測(cè)試頁(yè)面:IE、火狐彈出"hello world",而chrome,safari,opera毫無(wú)反應(yīng)。
以下是小段測(cè)試代碼(刻意修改domain,讓父頁(yè)面和子頁(yè)面為不同域頁(yè)面):
1.父頁(yè)面代碼:
復(fù)制代碼 代碼如下:

<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.子頁(yè)面代碼:
復(fù)制代碼 代碼如下:

<script>
try{
top.name;
}catch(e){
document.domain = 'nunumick.me';
top.doTest();
}
</script>

以上代碼目的是嘗試在訪問(wèn)異常時(shí)動(dòng)態(tài)修改domain達(dá)到順利訪問(wèn),但webkit內(nèi)核瀏覽器粗暴地報(bào)錯(cuò)而非拋出可截獲的異常,其他瀏覽器均如期運(yùn)行。

chrome錯(cuò)誤信息:

據(jù)了解,采用此類try catch方式做安全可行性判斷的并不只是個(gè)別現(xiàn)象,如DOJO

復(fù)制代碼 代碼如下:

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
復(fù)制代碼 代碼如下:

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). */ }

還有很多網(wǎng)友的反饋:chrome bug report

以上代碼在chrome,safari,opera均不適用。翻了一些資料,記錄在此:
1.html5 security location
2.webkit dev lists
從webkit開(kāi)發(fā)人員的討論消息中看到,他們承認(rèn)這個(gè)問(wèn)題但并不情愿去改正,holly shit!

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

绥宁县| 综艺| 山西省| 龙泉市| 义马市| 丰县| 浑源县| 湟源县| 睢宁县| 佛冈县| 福鼎市| 蒲江县| 靖宇县| 浦县| 浙江省| 轮台县| 龙江县| 沂源县| 久治县| 旅游| 晋中市| 和硕县| 大港区| 五大连池市| 太仓市| 武清区| 石屏县| 阜阳市| 高雄市| 英吉沙县| 延长县| 美姑县| 阜阳市| 蓝田县| 陆河县| 崇明县| 富宁县| 盘锦市| 横山县| 湘乡市| 临汾市|