以下資訊以開發人員為對象,針對應用程式存在 Path Traversal 漏洞。
有什麼變動?
從 2018 年 1 月 16 日起,Google Play 已開始阻止任何含有 Path traversal 漏洞的新應用程式或更新發佈。請參閱 Play Console 中的通知。在 Play Console 中顯示的限期過後,任何含有未修復安全漏洞的應用程式可能從 Google Play 中移除。
需要採取行動
- 登入 Play Console 並導覽至「警示」部分,查看哪些應用程式受到影響及解決問題的限期。
- 更新受影響的應用程式並修復漏洞。
- 提交受影響應用程式的更新版本。
重新提交後,您的應用程式將再次接受審核,此程序可能需時幾小時。如果應用程式通過審核並成功發佈,則您無需採取進一步行動。如果應用程式未能通過審核,則新的應用程式版本將不會發佈,而您將收到電郵通知。
其他詳細資料
如果未正確驗證傳入的 Uri 參數,在匯入的 ContentProviders 中實行 openFile 可能容易受到攻擊。惡意應用程式可以供應刻意營造的 Uri (例如含有「/../」的 Uri) 誘使您的應用程式傳回預定目錄以外檔案的 ParcelFileDescriptor,從而允許惡意應用程式存取任何您的應用程式可以存取的檔案。
有兩個消除 ContentProvider 中 Path Traversal 漏洞的建議策略:
1. 如果 ContentProvider 不需要向其他應用程式公開:
- 您可以在 Manifest 中修改受影響 ContentProvider 的 <provider> 標籤,以設定 android:exported=”false”。這將防止其他應用程式傳送 Intent 給受影響的 ContentProvider。
- 您也可以將 android:permission 屬性設為 android:protectionLevel=“signature” 的權限,以防止其他開發人員所編寫的應用程式傳送 Intent 給受影響的 ContentProvider。
2. 如果 ContentProvider 需要向其他應用程式公開:
您必須正確確定含有 Path traversal 字元的 openFile 輸入不能導致您的應用程式傳回未預期的檔案。您可以透過檢查檔案的 canonical path 來達到這個目的。例如:
public ParcelFileDescriptor openFile (Uri uri, String mode)
throws FileNotFoundException {
File f = new File(DIR, uri.getLastPathSegment());
if (!f.getCanonicalPath().startsWith(DIR)) {
throw new IllegalArgumentException();
}
return ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
}
警告:請注意,對 Uri 參數調用 getLastPathSegment 並不安全。惡意應用程式可以供應編碼的 Uri 路徑 (如 %2F..%2F..path%2Fto%2Fsecret.txt),因此 getLastPathSegment 的結果將是 /../../path/to/secret.txt。例如,以下的實行仍容易受到攻擊。
public ParcelFileDescriptor openFile(Uri uri, String mode){
File f = new File(DIR, uri.getLastPathSegment());
return ParcelFileDescriptor.open(f, ParcelFileDescriptor.MODE_READ_ONLY);
}
我們樂意提供協助
如有關於此漏洞的技術問題,請在 Stack Overflow 發佈並加上「android-security」標籤。如需釐清解決此問題所需的步驟,您可以聯絡我們的開發人員支援團隊。