不安全地使用深层链接
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
OWASP 类别: MASVS-PLATFORM:平台互动
概览
与深层链接相关的安全风险源于其核心功能:在移动应用中实现流畅的导航和互动。深层链接漏洞源于深层链接实现或处理方面的弱点。恶意行为者可能会利用这些缺陷来获取特权函数或数据的访问权限,这可能会导致数据泄露、隐私权侵犯和未经授权的操作。攻击者可通过各种技术来利用这些漏洞,例如深层链接劫持和数据验证攻击。
影响
缺少适当的深层链接验证机制或以不安全的方式使用深层链接有助于恶意用户在有漏洞的应用的权限环境中执行攻击,例如绕过主机验证、跨应用脚本和远程执行代码。这可能会导致未经授权访问敏感数据或功能,具体取决于应用的性质。
缓解措施
防止深层链接被盗用
从设计上讲,Android 允许多个应用为同一深层链接 URI 注册 intent 过滤器。为了防止恶意应用拦截要用于您的应用的深层链接,请在应用的 AndroidManifest
内的 intent-filter
中实现 android:autoVerify
属性。这样一来,用户就可以选择他们首选的应用来处理深层链接,从而确保操作符合预期,并防止恶意应用自动解读这些链接。
Android 12 引入了更严格的 Web intent 处理方式,以提高安全性。现在,应用必须通过 Android App Links 或用户在系统设置中进行选择,才能处理来自特定网域的链接。这可防止应用盗用不应处理的链接。
如需为您的应用启用链接处理验证,请添加与以下格式匹配的 intent 过滤器(此示例摘自验证 Android App Links 文档):
<!-- 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>
实现可靠的数据验证
深层链接可以包含提供给目标 intent 的其他参数,例如用于执行进一步操作。严格的数据验证是安全深层链接处理的基础。开发者应仔细验证和清理来自深层链接的所有传入数据,以防止恶意代码或值被注入合法应用中。为此,您可以将任何深层链接参数的值与预定义的预期值许可名单进行对比。
应用应先检查其他相关的内部状态(例如身份验证状态或授权),然后再公开敏感信息。例如,完成游戏关卡时获得的奖励。在这种情况下,值得验证已完成关卡这一前提条件,并在未完成关卡时重定向到主屏幕。
资源
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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/)"]]