Mittente di intent in attesa
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Categoria OWASP: MASVS-CODE: Code Quality
Panoramica
L'utilizzo di PendingIntent.getCreator*()
o PendingIntent.getTarget*()
per determinare se considerare attendibile il mittente di un PendingIntent crea un rischio di sfruttamento.
PendingIntent.getCreator*()
o
PendingIntent.getTarget*()
restituisce il creatore di PendingIntent, che non sempre corrisponde al mittente. Il creator potrebbe essere attendibile, ma
il mittente non deve mai essere considerato attendibile, in quanto potrebbe trattarsi di un'app dannosa
che ha acquisito l'intent in attesa di un'altra app utilizzando vari meccanismi, ad esempio:
Un esempio di utilizzo legittimo di PendingIntent.getCreator*()
o PendingIntent.getTarget*()
sarebbe mostrare
l'icona dell'app che verrà avviata da PendingIntent.
Impatto
Affidarsi al mittente di un PendingIntent perché hai eseguito una query (e ti fidi) del creator
può portare a vulnerabilità. Se un'app considera attendibile il mittente di PendingIntent in base al suo creatore e poi condivide la sua logica di autenticazione o autorizzazione, ogni volta che il mittente di PendingIntent è un'app dannosa, ciò comporterà un bypass dell'autenticazione o potenzialmente anche l'esecuzione di codice remoto in base a input non attendibili e invalidati, a seconda dell'implementazione del codice dell'applicazione vulnerabile.
Mitigazioni
Distinguere tra mittente e creator
Qualsiasi tipo di logica di autenticazione o autorizzazione eseguita durante la ricezione di un
PendingIntent non deve basarsi su presupposti relativi al
creatore di PendingIntent identificato utilizzando PendingIntent.getCreator*()
o PendingIntent.getTarget*()
.
Utilizzare metodi alternativi per convalidare i chiamanti
Se devi autenticare il chiamante, anziché utilizzare PendingIntent, devi
utilizzare un servizio o un ContentProvider. Entrambi consentono di recuperare l'UID del chiamante
con Binder.getCallingUid() quando ti trovi nel contesto dell'invio di un
IPC in entrata. L'UID può essere interrogato in un secondo momento utilizzando
PackageManager.getPackagesForUid().
Un altro approccio, disponibile dal livello API 34, consiste nell'utilizzare
BroadcastReceiver.getSentFromUid() o
BroadcastReceiver.getSentFromPackage() se il mittente ha attivato la condivisione
dell'identità durante la trasmissione utilizzando BroadcastOptions.isShareIdentityEnabled().
Devi sempre controllare se il pacchetto chiamante ha la firma prevista, in quanto
i pacchetti caricati lateralmente possono avere nomi di pacchetti che si sovrappongono a quelli del Play
Store.
Risorse
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-27 UTC."],[],[],null,["# Sender of Pending Intents\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nUsing [`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1) or [`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1) to determine whether to trust a PendingIntent's sender creates an\nexploitation risk.\n\n[`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1) or\n[`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1) returns the PendingIntent's\ncreator, which does not always match its sender. The creator may be trusted, but\nthe sender should **never** be trusted, as the sender might be a malicious app\nthat acquired another app's PendingIntent using a variety of mechanisms, for\nexample:\n\n- from [`NotificationListenerService`](/reference/android/service/notification/NotificationListenerService)\n- legitimate use cases that are part of the vulnerable app.\n\nAn example of a legitimate use of [`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1) or [`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1) would be to show\nthe icon of the app that will be started by the PendingIntent.\n\nImpact\n------\n\nTrusting a PendingIntent's sender because you queried (and trust) the creator\ncan lead to vulnerabilities. If an app trusts the PendingIntent's sender based\non its creator, and then shares its authentication or authorization logic, then\nwhenever the PendingIntent's sender is a malicious app, this would lead to an\nauthentication bypass or potentially even remote code execution based on\ninvalidated, untrusted input, depending on the implementation of the vulnerable\napplication's code.\n\nMitigations\n-----------\n\n### Distinguish between sender and creator\n\nAny type of authentication or authorization logic performed when receiving a\nPendingIntent must not be based on assumptions regarding the PendingIntent's\ncreator identified using either [`PendingIntent.getCreator*()`](/reference/android/app/PendingIntent#public-methods_1)\nor [`PendingIntent.getTarget*()`](/reference/android/app/PendingIntent#public-methods_1).\n\n### Use alternative ways to validate callers\n\nIf you need to authenticate the caller, instead of using PendingIntent, you\nshould use a Service or ContentProvider -- both allow fetching the caller UID\nwith [Binder.getCallingUid()](/reference/android/os/Binder#getCallingUid()) when you are in the context of dispatching an\nincoming IPC. The UID can be queried later by using\n[PackageManager.getPackagesForUid()](/reference/android/content/pm/PackageManager#getPackagesForUid(int)).\n\nAnother approach, available from API level 34, would be to use\n[BroadcastReceiver.getSentFromUid()](/reference/android/content/BroadcastReceiver#getSentFromUid()) or\n[BroadcastReceiver.getSentFromPackage()](/reference/android/content/BroadcastReceiver#getSentFromPackage()) if the sender opted in to sharing\nidentity during broadcast using [BroadcastOptions.isShareIdentityEnabled()](/reference/android/app/BroadcastOptions#isShareIdentityEnabled()).\n\nYou should always check if the calling package has the expected signature, as\nsideloaded packages can have package names overlapping with ones from the Play\nStore.\n\nResources\n---------\n\n- [Pending Intent](/reference/android/app/PendingIntent)"]]