待处理 intent
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
OWASP 类别:MASVS-PLATFORM:平台互动
概览
PendingIntent
是对系统维护的令牌的引用。应用 A 可以将 PendingIntent 传递到应用 B,以允许应用 B 代表应用 A 执行预定义的操作,无论应用 A 是否仍在运行。
风险:可变的待处理 intent
PendingIntent 是可变的,这意味着应用 B 可以按照 fillIn()
文档中所述的逻辑更新用于指定操作的内部 intent。换言之,恶意应用可能会修改 PendingIntent 的某些未填充字段,从而允许攻击者访问存在漏洞的应用中原本不支持导出的组件。
影响
此漏洞的影响因不支持导出的目标应用功能的实现情况而异。
缓解措施
一般措施
确保已设置操作、组件和软件包,以避免出现最严重的漏洞:
Kotlin
val intent = Intent(intentAction)
// Or other component setting APIs e.g. setComponent, setClass
intent.setClassName(packageName, className)
PendingIntent pendingIntent =
PendingIntent.getActivity(
context,
/* requestCode = */ 0,
intent, /* flags = */ PendingIntent.FLAG_IMMUTABLE
)
Java
Intent intent = new Intent(intentAction);
// Or other component setting APIs e.g. setComponent, setClass
intent.setClassName(packageName, className);
PendingIntent pendingIntent =
PendingIntent.getActivity(
getContext(),
/* requestCode= */ 0,
intent, /* flags= */ 0);
标记 IMMUTABLE
如果您的应用以 Android 6(API 级别 23)或更高版本为目标平台,请指定可变性。例如,要实现此目的,可以使用 FLAG_IMMUTABLE
来防止恶意应用填充未填充的字段:
Kotlin
val pendingIntent =
PendingIntent.getActivity(
context,
/* requestCode = */ 0,
Intent(intentAction),
PendingIntent.FLAG_IMMUTABLE)
Java
PendingIntent pendingIntent =
PendingIntent.getActivity(
getContext(),
/* requestCode= */ 0,
new Intent(intentAction),
PendingIntent.FLAG_IMMUTABLE);
在 Android 11(API 级别 30)及更高版本中,您必须指定要将哪些字段设置为可变字段,以缓解此类意外漏洞。
资源
风险:重放待处理 intent
除非设置了 FLAG_ONE_SHOT 标志,否则 PendingIntent 便可以重放。请务必使用 FLAG_ONE_SHOT,以避免重放攻击(执行不应重复的操作)。
影响
此漏洞的影响因 intent 接收端的实现情况而异。如果恶意应用利用在未设置 FLAG_ONE_SHOT 标志的情况下创建的 PendingIntent,便可以捕获并重复使用相应 intent,以重复执行本应只能执行一次的操作。
缓解措施
不应多次触发的待处理 intent 应使用 FLAG_ONE_SHOT 标志来避免重放攻击。
Kotlin
val pendingIntent =
PendingIntent.getActivity(
context,
/* requestCode = */ 0,
Intent(intentAction),
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT)
Java
PendingIntent pendingIntent =
PendingIntent.getActivity(
getContext(),
/* requestCode= */ 0,
new Intent(intentAction),
PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT);
资源
资源
为您推荐
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-12-13。
[null,null,["最后更新时间 (UTC):2023-12-13。"],[],[],null,["# Pending intents\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-PLATFORM: Platform Interaction](https://mas.owasp.org/MASVS/09-MASVS-PLATFORM)\n\n\nOverview\n--------\n\nA [`PendingIntent`](/reference/android/app/PendingIntent) is a reference to a token maintained by the system. Application A can pass a PendingIntent to application B in order to allow application B to execute predefined actions on behalf of application A; regardless of whether application A is still alive.\n\nRisk: Mutable Pending Intents\n-----------------------------\n\nA PendingIntent can be mutable, which means that the inner intent that specifies the action can be updated by application B following the logic described in the [`fillIn()`](/reference/android/content/Intent#fillIn(android.content.Intent,%20int)) documentation. In other words, the unfilled fields of a PendingIntent can be modified by a malicious app and allow access to otherwise non-exported components of the vulnerable application.\n\n### Impact\n\nThe impact of this vulnerability varies depending on the implementation of the targeted unexported functionality of the app.\n\n### Mitigations\n\n#### General\n\nMake sure action, component, and package are set to avoid the worst vulnerabilities: \n\n### Kotlin\n\n val intent = Intent(intentAction)\n\n // Or other component setting APIs e.g. setComponent, setClass\n intent.setClassName(packageName, className)\n\n PendingIntent pendingIntent =\n PendingIntent.getActivity(\n context,\n /* requestCode = */ 0,\n intent, /* flags = */ PendingIntent.FLAG_IMMUTABLE\n )\n\n### Java\n\n Intent intent = new Intent(intentAction);\n\n // Or other component setting APIs e.g. setComponent, setClass\n intent.setClassName(packageName, className);\n\n PendingIntent pendingIntent =\n PendingIntent.getActivity(\n getContext(),\n /* requestCode= */ 0,\n intent, /* flags= */ 0);\n\n#### Flag IMMUTABLE\n\nIf your app targets Android 6 (API level 23) or higher, [specify mutability](/guide/components/intents-filters#DeclareMutabilityPendingIntent). For example, this can be done by using [`FLAG_IMMUTABLE`](/reference/android/app/PendingIntent#FLAG_IMMUTABLE) to prevent unfilled fields from being filled in by a malicious application: \n\n### Kotlin\n\n val pendingIntent =\n PendingIntent.getActivity(\n context,\n /* requestCode = */ 0,\n Intent(intentAction),\n PendingIntent.FLAG_IMMUTABLE)\n\n### Java\n\n PendingIntent pendingIntent =\n PendingIntent.getActivity(\n getContext(),\n /* requestCode= */ 0,\n new Intent(intentAction),\n PendingIntent.FLAG_IMMUTABLE);\n\nOn Android 11 (API level 30) and higher, you have to specify which fields to make mutable, which mitigates accidental vulnerabilities of this type.\n\n### Resources\n\n- [Remediation of PendingIntent vulnerability](https://support.google.com/faqs/answer/9267555)\n\n- [Blog post about the vulnerability](https://valsamaras.medium.com/pending-intents-a-pentesters-view-92f305960f03)\n\n*** ** * ** ***\n\nRisk: Replaying Pending Intents\n-------------------------------\n\nA PendingIntent can be replayed unless the [FLAG_ONE_SHOT](/reference/android/app/PendingIntent#FLAG_ONE_SHOT) flag is set. It is important to use FLAG_ONE_SHOT to avoid replay attacks (performing actions that should not be repeatable).\n\n### Impact\n\nThe impact of this vulnerability varies depending on the implementation of the receiving end of the intent. A malicious app exploiting a PendingIntent that was created without setting the FLAG_ONE_SHOT flag could capture and re-use the intent to repeat actions that should only be able to be done once.\n\n### Mitigations\n\nPending Intents not intended to be fired multiple times should use the [FLAG_ONE_SHOT](/reference/android/app/PendingIntent#FLAG_ONE_SHOT) flag to avoid replay attacks. \n\n### Kotlin\n\n val pendingIntent =\n PendingIntent.getActivity(\n context,\n /* requestCode = */ 0,\n Intent(intentAction),\n PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_ONE_SHOT)\n\n### Java\n\n PendingIntent pendingIntent =\n PendingIntent.getActivity(\n getContext(),\n /* requestCode= */ 0,\n new Intent(intentAction),\n PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_ONE_SHOT);\n\n### Resources\n\n- [PendingIntent.FLAG_ONE_SHOT](/reference/android/app/PendingIntent#FLAG_ONE_SHOT)\n\n*** ** * ** ***\n\nResources\n---------\n\n- [PendingIntent documentation](/reference/android/app/PendingIntent)\n\n- [PendingIntent and intent filters](/guide/components/intents-filters#PendingIntent)\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [Intent redirection](/topic/security/risks/intent-redirection)"]]