待處理意圖
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
OWASP 類別:MASVS-PLATFORM:平台互動
總覽
PendingIntent
會參照系統維護的權杖。應用程式 A 可將 PendingIntent 傳遞至應用程式 B,讓應用程式 B 代表應用程式 A 執行預先定義的動作;無論應用程式 A 是否仍有效,結果都是這樣。
風險:可變動的待處理意圖
PendingIntent 可以變動,這表示應用程式 B 可按照 fillIn()
說明文件中所述的邏輯,更新用於指定動作的內部意圖。換句話說,惡意應用程式可以修改 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) 及以上版本中,您必須指定要變動的欄位,以降低該類型的意外安全漏洞。
資源
風險:重播待處理意圖
除非設定 FLAG_ONE_SHOT 旗標,否則可以重播 PendingIntent。請務必使用 FLAG_ONE_SHOT 以避免重播攻擊 (執行不應重複的操作)。
影響
此安全漏洞造成的影響會因意圖接收端的實作方式而不同。惡意應用程式會利用未設定 FLAG_ONE_SHOT 旗標時所建立的 PendingIntent 來擷取及重複使用意圖,以重複執行只應執行一次的動作。
因應措施
不應多次觸發的待處理意圖應使用 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);
資源
資源
為您推薦
- 注意:系統會在 JavaScript 關閉時顯示連結文字
- 意圖重新導向
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2024-01-05 (世界標準時間)。
[[["容易理解","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"]],["上次更新時間:2024-01-05 (世界標準時間)。"],[],[],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)"]]