Expéditeur des intents en attente
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Catégorie OWASP : MASVS-CODE : qualité du code
Présentation
L'utilisation de PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
pour déterminer s'il faut faire confiance à l'expéditeur d'un PendingIntent crée un risque d'exploitation.
PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
renvoie le créateur de PendingIntent, qui ne correspond pas toujours à son expéditeur. Le créateur peut être digne de confiance, mais l'expéditeur ne doit jamais l'être, car il peut s'agir d'une application malveillante qui a acquis l'Intent en attente d'une autre application à l'aide de divers mécanismes, par exemple :
Un exemple d'utilisation légitime de PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
consiste à afficher l'icône de l'application qui sera lancée par PendingIntent.
Impact
Faire confiance à l'expéditeur d'une PendingIntent parce que vous avez interrogé (et faites confiance) au créateur peut entraîner des failles de sécurité. Si une application fait confiance à l'expéditeur de PendingIntent en fonction de son créateur, puis partage sa logique d'authentification ou d'autorisation, cela entraînerait un contournement de l'authentification ou potentiellement même une exécution de code à distance basée sur une entrée non valide et non fiable, chaque fois que l'expéditeur de PendingIntent est une application malveillante, en fonction de l'implémentation du code de l'application vulnérable.
Stratégies d'atténuation
Distinguer l'expéditeur du créateur
Tout type de logique d'authentification ou d'autorisation effectué lors de la réception d'une PendingIntent ne doit pas être basé sur des hypothèses concernant le créateur de la PendingIntent identifié à l'aide de PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
.
Utiliser d'autres méthodes pour valider les appelants
Si vous devez authentifier l'appelant, au lieu d'utiliser PendingIntent, vous devez utiliser un service ou un ContentProvider. Les deux permettent de récupérer l'UID de l'appelant avec Binder.getCallingUid() lorsque vous êtes dans le contexte de l'envoi d'un IPC entrant. L'UID peut être interrogé ultérieurement à l'aide de PackageManager.getPackagesForUid().
Une autre approche, disponible à partir du niveau d'API 34, consiste à utiliser BroadcastReceiver.getSentFromUid() ou BroadcastReceiver.getSentFromPackage() si l'expéditeur a choisi de partager son identité lors de la diffusion à l'aide de BroadcastOptions.isShareIdentityEnabled().
Vous devez toujours vérifier si le package appelant possède la signature attendue, car les packages chargés de manière indépendante peuvent avoir des noms de package qui se chevauchent avec ceux du Play Store.
Ressources
Le contenu et les exemples de code de cette page sont soumis aux licences décrites dans la Licence de contenu. Java et OpenJDK sont des marques ou des marques déposées d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/27 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)"]]