以不安全的方式使用深層連結
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
OWASP 類別: MASVS-PLATFORM:平台互動
總覽
深層連結的安全性風險源自於其核心功能,也就是在行動應用程式中提供順暢的導覽和互動體驗。深層連結漏洞源自於深層連結的實作或處理方式有缺陷。惡意人士可能會利用這些安全漏洞,獲得特殊權限功能或資料的存取權,進而可能導致資料侵害、侵犯隱私權,以及未經授權的動作。攻擊者可以透過各種技巧利用這些安全漏洞,例如深層連結劫持和資料驗證攻擊。
影響
如果缺乏適當的深層連結驗證機制,或不安全地使用深層連結,惡意使用者就可能會執行攻擊,例如主機驗證繞過、跨應用程式指令碼,以及在有安全漏洞的應用程式權限內容中執行遠端程式碼。視應用程式的性質而定,這可能會導致未經授權存取機密資料或函式。
因應措施
防止深層連結遭到入侵
根據設計,Android 允許多個應用程式為相同的深層連結 URI 註冊意圖篩選器。如要防止惡意應用程式攔截應用程式專用的深層連結,請在應用程式的 AndroidManifest
內的 intent-filter
中實作 android:autoVerify
屬性。使用者可以選取偏好的應用程式來處理深層連結,確保所需的操作,並防止惡意應用程式自動解讀深層連結。
Android 12 引入更嚴格的網頁意圖處理機制,以提升安全性。應用程式現在必須經過驗證,才能處理特定網域的連結,方法是透過 Android 應用程式連結或系統設定中的使用者選項。這可避免應用程式將不應處理的連結劫持。
如要為應用程式啟用連結處理驗證功能,請新增符合下列格式的意圖篩選器 (這個範例取自「驗證 Android 應用程式連結」說明文件):
<!-- Make sure you explicitly set android:autoVerify to "true". -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- If a user clicks on a shared link that uses the "http" scheme, your
app should be able to delegate that traffic to "https". -->
<data android:scheme="http" />
<data android:scheme="https" />
<!-- Include one or more domains that should be verified. -->
<data android:host="..." />
</intent-filter>
導入完善的資料驗證機制
深層連結可包含額外參數,以便提供給目標意圖,例如執行進一步動作。安全深層連結處理的基礎是嚴格的資料驗證。開發人員應仔細驗證並處理深層連結傳入的所有資料,以免惡意程式碼或值在合法應用程式中注入。您可以透過檢查任何深層連結參數的值,與預先定義的預期值許可清單進行比對,實作這項功能。
應用程式應先檢查其他相關的內部狀態 (例如驗證狀態或授權),再揭露機密資訊。舉例來說,當使用者完成遊戲關卡時,系統就會提供獎勵。在這種情況下,建議您驗證已完成關卡的先決條件,如果沒有,則重新導向至主畫面。
資源
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Unsafe use of deep links\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-PLATFORM: Platform Interaction](https://mas.owasp.org/MASVS/09-MASVS-PLATFORM)\n\nOverview\n--------\n\nThe security risks associated with deep links stem from their core capability of\nenabling seamless navigation and interaction within mobile applications. Deep\nlink vulnerabilities arise from weaknesses in the implementation or handling of\ndeep links. These flaws can be exploited by malicious actors to gain access to\nprivileged functions or data, potentially resulting in data breaches, privacy\nviolations, and unauthorized actions. Attackers can exploit these\nvulnerabilities through various techniques, such as deep link hijacking and data\nvalidation attacks.\n\nImpact\n------\n\nThe lack of a proper deep link validation mechanism, or the unsafe use of\ndeeplinks, can aid malicious users in performing attacks such as host validation\nbypass, cross-app scripting, and remote code execution within the permissions\ncontext of the vulnerable application. Depending on the nature of the\napplication, this can result in unauthorized access to sensitive data or\nfunctions.\n\nMitigations\n-----------\n\n### Prevent deep link hijacking\n\nBy design, Android allows multiple apps to register intent filters for the same\ndeep link URI. To prevent malicious apps from intercepting deep links intended\nfor your app, implement the `android:autoVerify` attribute in `intent-filter`\nwithin the application's `AndroidManifest`. This allows users to select their\npreferred app for handling deep links, ensuring the intended operation and\npreventing malicious applications from automatically interpreting them.\n\nAndroid 12 [introduced](/about/versions/12/behavior-changes-all#web-intent-resolution) stricter handling of web intents to improve security.\nApps must now be verified to handle links from specific domains, either through\nAndroid App Links or user selection in system settings. This prevents apps from\nhijacking links they shouldn't handle.\n\nTo enable link handling verification for your app, add intent filters that match\nthe following format (this example is taken from the [Verify Android App\nLinks](/training/app-links/verify-android-applinks) documentation): \n\n \u003c!-- Make sure you explicitly set android:autoVerify to \"true\". --\u003e\n \u003cintent-filter android:autoVerify=\"true\"\u003e\n \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n \n \u003c!-- If a user clicks on a shared link that uses the \"http\" scheme, your\n app should be able to delegate that traffic to \"https\". --\u003e\n \u003cdata android:scheme=\"http\" /\u003e\n \u003cdata android:scheme=\"https\" /\u003e\n \n \u003c!-- Include one or more domains that should be verified. --\u003e\n \u003cdata android:host=\"...\" /\u003e\n \u003c/intent-filter\u003e\n\n### Implement robust data validation\n\nDeep links can include additional parameters that are served to the target\nintent, for example, to perform further actions. The foundation of secure deep\nlink handling is stringent data validation. All incoming data from deep links\nshould be meticulously validated and sanitized by developers to prevent\nmalicious code or values from being injected within the legitimate application.\nThis can be implemented by checking the value of any deep link parameter against\na predefined allowlist of expected values.\n\nApps should check other relevant internal states, such as authentication state,\nor authorization, before exposing sensitive information. An example might be a\nreward for completing a level of a game. In this case it's worth validating the\nprecondition of having completed the level, and redirecting to the main screen\nif not.\n\nResources\n---------\n\n- [Verify Android App Links](/training/app-links/verify-android-applinks)\n- [Handling Android App Links](/training/app-links)\n- [Web intent resolution](/about/versions/12/behavior-changes-all#web-intent-resolution)\n- [Account takeover intercepting magic link for Arrive app](https://hackerone.com/reports/855618)\n- [Deep Links \\& WebViews Exploitations Part I](https://www.justmobilesec.com/en/blog/deep-links-webviews-exploitations-part-I)\n- [Deep Links \\& WebViews Exploitations Part II](https://www.justmobilesec.com/en/blog/deep-links-webviews-exploitations-part-II)\n- [Recent suggestion of a deep link issue in Jetpack Navigation](https://swarm.ptsecurity.com/android-jetpack-navigation-go-even-deeper/)"]]