2014-11-24 47 views
0


XSS漏洞發送URL Safari瀏覽器的iOS

,當我得到的代碼掃描後, 報告顯示一個XSS漏洞發生了,當我嘗試在Safari的應用程序打開一個網頁。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[event objectForKey:@"url"]]]; 

'event'是一個NSDictionary,其中我通過NSURL從我的服務器獲取。

我明白爲避免XSS,您應該對輸出進行編碼。
但這樣會弄亂URL並且Safari無法打開正確的網頁?

或者還有其他的東西導致這個問題?

我對安全性並不熟悉,所以任何指針都將不勝感激。

在此先感謝!

+1

我認爲這是因爲它是一個動態創建的URL,在將它傳遞給openURL之前,您並未進行驗證: – Tim 2014-11-24 12:05:57

回答

0

當應用程序嘗試反映href屬性中的輸出時,可能會出現基於URL上下文的XSS。

<a href="DATA_REFLECTS_HERE">DATA_REFLECTS_HERE</a> 

正如你可以看到相同的變量可以使用2 diffirent上下文。第一個是在href裏面,第二個是直接HTML上下文。

大多數命令XSS有效載荷(javascript:alert(1)等)和緩解可以在以下示例中找到。

/** 
* XSS protection function for URL context 
* @usecases 
* <a href="use this function if output reflects here">click</a> 
* <img src="use this function if output reflects here"> 
* <iframe src="use this function if output reflects here"> 
* @description 
* Only allows URLs that start with http(s) or ftp. e.g., 
* https://www.google.com 
* Protection against JavaScript, VBScript and Data URI JavaScript code execution etc. 
* @author Ashar Javed 
* @Link https://twitter.com/soaj1664ashar 
* @demo http://xssplaygroundforfunandlearn.netai.net/final.html 
*/ 
function urlContextCleaner($url) { 
    if(preg_match("#^(?:(?:https?|ftp):{1})\/\/[^\"\s\\\\]*.[^\"\s\\\\]*$#iu",(string)$url,$match)) 
    { 
     return $match[0]; 
    } 
    else { 
     $noxss='javascript:void(0)'; 
     return $noxss; 
    } 
} 

從抓起:https://github.com/symphonycms/xssfilter/blob/master/lib/xss.php

旁邊,就可以解決這個問題,而不必太麻煩了。如果您知道url只能是http協議,那麼在href屬性中添加http(s)前綴內聯,並對所有類型的引號進行編碼(單,雙和反勾號)

對於HTML上下文,只需使用經典編碼方法。