Webkit的跨域安全問題說明
以下是小段測試代碼(刻意修改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>
以上代碼目的是嘗試在訪問異常時動態(tài)修改domain達到順利訪問,但webkit內(nèi)核瀏覽器粗暴地報錯而非拋出可截獲的異常,其他瀏覽器均如期運行。
chrome錯誤信息:

據(jù)了解,采用此類try catch方式做安全可行性判斷的并不只是個別現(xiàn)象,如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). */ }
還有很多網(wǎng)友的反饋:chrome bug report
以上代碼在chrome,safari,opera均不適用。翻了一些資料,記錄在此:
1.html5 security location
2.webkit dev lists
從webkit開發(fā)人員的討論消息中看到,他們承認這個問題但并不情愿去改正,holly shit!
- jquery下利用jsonp跨域訪問實現(xiàn)方法
- jquery下異步提交表單 異步跨域提交表單
- 基于Jquery的跨域傳輸數(shù)據(jù)(JSONP)
- Ajax跨域代理訪問網(wǎng)絡資源的實現(xiàn)代碼
- 使用JSON實現(xiàn)數(shù)據(jù)的跨域傳輸?shù)膒hp代碼
- jquery $.getJSON()跨域請求
- JS跨域總結(jié)
- js iframe跨域訪問(同主域/非同主域)分別深入介紹
- 借助script進行Http跨域請求:JSONP實現(xiàn)原理及代碼
- JQuery的Ajax跨域請求原理概述及實例
- UEditor 編輯器跨域上傳解決方法
- AJAX的跨域訪問-兩種有效的解決方法介紹
- Ajax跨域查詢完美解決通過$.getJSON()實現(xiàn)
- PHP如何利用P3P實現(xiàn)跨域
- 如何設置iframe高度自適應在跨域情況下的可用方法
- 完美解決AJAX跨域問題
- AJAX跨域請求json數(shù)據(jù)的實現(xiàn)方法
- 用iframe設置代理解決ajax跨域請求問題
- jquery ajax jsonp跨域調(diào)用實例代碼
- jquery ajax跨域解決方法(json方式)
- jquery的ajax和getJson跨域獲取json數(shù)據(jù)的實現(xiàn)方法
- 用jQuery與JSONP輕松解決跨域訪問的問題
- php跨域cookie共享使用方法
- JavaScript使用HTML5的window.postMessage實現(xiàn)跨域通信例子
- 關(guān)于JavaScript跨域問題及實時刷新解決方案
- IE9版本以下ajax 跨域問題可行解決方法
- js跨域問題淺析及解決方法優(yōu)缺點對比
- 使用jsonp完美解決跨域問題
- 5種處理js跨域問題方法匯總
- js同源策略詳解
- 深入淺析同源策略和跨域訪問
相關(guān)文章
JavaScript跨平臺的開源框架NativeScript
本文給大家分享的是一款使用javascript來構(gòu)建跨平臺原生移動應用的開源框架--NativeScript,可以使用JavaScript開發(fā)跨平臺、真正原生的iOS, Android 和 Windows 移動App。開發(fā)人員使用NativeScript提供的庫來構(gòu)建應用UI,其抽象了各種原生平臺之間的不同。2015-03-03javascript設計模式 – 備忘錄模式原理與用法實例分析
這篇文章主要介紹了javascript設計模式 – 備忘錄模式,結(jié)合實例形式分析了javascript備忘錄模式相關(guān)概念、原理、用法及操作注意事項,需要的朋友可以參考下2020-04-04JavaScript+CSS實現(xiàn)模態(tài)框效果
這篇文章主要為大家詳細介紹了JavaScript+CSS實現(xiàn)模態(tài)框效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-07-07JavaScript遍歷求解數(shù)獨問題的主要思路小結(jié)
數(shù)獨游戲非常流行,其規(guī)則就是1到9數(shù)字填入9*9宮格并要求每一行、每一列、每一個粗線(小型)宮內(nèi)的數(shù)字不重復,對此我們來看一下JavaScript遍歷求解數(shù)獨問題的主要思路小結(jié)2016-06-06