英文:
PendingIntent with FLAG_MUTABLE risk examples?
问题
如Android开发者文档中的PendingIntent部分所述,接收PendingIntent的应用程序可以修改PendingIntent的未填充字段,从而允许访问否则不可导出的受影响应用程序的组件:
风险:可变PendingIntent
PendingIntent可以是可变的,这意味着内部意图可以根据应用程序B中fillIn()文档中描述的逻辑进行更新。换句话说,恶意应用程序可以修改PendingIntent的未填充字段,并允许访问否则不可导出的受影响应用程序的组件。
因此,由于这个风险,他们为在应用程序源代码中使用PendingIntent而没有可变性标志的情况创建了Lint警告,如在这个问题中所示。
您能否展示一个如何利用这种风险的示例或真实用例?
代码片段有助于理解,也会受到赞赏。
英文:
As stated in the PendingIntent section of the Mitigate security risks in your app
in the Android Developer documentation, an application that receives a PendingIntent can modify unfilled fields of a PendingIntent to allow access to otherwise non-exported components of the vulnerable application
:
> Risk: Mutable Pending Intents
>
> A 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() 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.
Because of this risk they created a Lint warning for app sources that use PendingIntents without mutability flag, as posted in this question
Can you show an example or a real use case of how such risk could be exploited?
Code snippets help understanding and are appreciated
答案1
得分: 1
以下是翻译好的代码部分:
val updatedPendingIntent = PendingIntent.getActivity(
context,
NOTIFICATION_REQUEST_CODE,
updatedIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
在 Build.VERSION_CODES.R 之前,默认情况下假定 PendingIntent 可变,除非设置了 FLAG_IMMUTABLE。从 Build.VERSION_CODES.S 开始,将需要在创建 PendingIntent 时明确指定其可变性,要么使用 (FLAG_IMMUTABLE},要么使用 FLAG_MUTABLE。强烈建议在创建 PendingIntent 时使用 FLAG_IMMUTABLE。只有在某些功能依赖于修改底层 intent 的情况下才应使用 FLAG_MUTABLE,例如,需要与内联回复或气泡一起使用的任何 PendingIntent。
请注意,代码中的大于符号(>)是HTML转义字符,用于表示引用文本的缩进,所以在翻译中没有包含它们。
英文:
Sample Code
val updatedPendingIntent = PendingIntent.getActivity(
context,
NOTIFICATION_REQUEST_CODE,
updatedIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
> Up until Build.VERSION_CODES.R, PendingIntents are assumed to be
> mutable by default, unless FLAG_IMMUTABLE is set. Starting with
> Build.VERSION_CODES.S, it will be required to explicitly specify the
> mutability of PendingIntents on creation with either (FLAG_IMMUTABLE}
> or FLAG_MUTABLE. It is strongly recommended to use FLAG_IMMUTABLE when
> creating a PendingIntent. FLAG_MUTABLE should only be used when some
> functionality relies on modifying the underlying intent, e.g. any
> PendingIntent that needs to be used with inline reply or bubbles.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论