Remetente de intents pendentes
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Categoria do OWASP: MASVS-CODE - Qualidade do código (link em inglês)
Visão geral
Usar PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
para determinar se o remetente de um PendingIntent é confiável cria um
risco de exploração.
PendingIntent.getCreator*()
ou
PendingIntent.getTarget*()
retorna o criador do
PendingIntent, que nem sempre corresponde ao remetente. O criador pode ser confiável, mas
o remetente nunca deve ser confiável, já que ele pode ser um app malicioso
que adquiriu o PendingIntent de outro app usando vários mecanismos, por
exemplo:
Um exemplo de uso legítimo de PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
seria mostrar
o ícone do app que será iniciado pela PendingIntent.
Impacto
Confiar no remetente de uma PendingIntent porque você consultou (e confia) no criador
pode levar a vulnerabilidades. Se um app confiar no remetente do PendingIntent com base no criador dele e compartilhar a lógica de autenticação ou autorização, sempre que o remetente do PendingIntent for um app malicioso, isso vai levar a uma violação de autenticação ou até mesmo à execução remota de código com base em entradas inválidas e não confiáveis, dependendo da implementação do código do aplicativo vulnerável.
Mitigações
Distinguir entre remetente e criador
Qualquer tipo de lógica de autenticação ou autorização realizada ao receber um
PendingIntent não pode se basear em pressupostos sobre o
criador do PendingIntent identificado usando PendingIntent.getCreator*()
ou PendingIntent.getTarget*()
.
Usar outras formas de validar autores de chamadas
Se você precisar autenticar o autor da chamada, em vez de usar PendingIntent, use um Service ou ContentProvider. Ambos permitem buscar o UID do autor da chamada com Binder.getCallingUid() quando você estiver no contexto de envio de um IPC de entrada. O UID pode ser consultado mais tarde usando
PackageManager.getPackagesForUid().
Outra abordagem, disponível a partir do nível 34 da API, seria usar BroadcastReceiver.getSentFromUid() ou BroadcastReceiver.getSentFromPackage() se o remetente tiver ativado o compartilhamento de identidade durante a transmissão usando BroadcastOptions.isShareIdentityEnabled().
Sempre verifique se o pacote de chamada tem a assinatura esperada, já que
pacotes transferidos por sideload podem ter nomes de pacotes que se sobrepõem aos da Play
Store.
Recursos
O conteúdo e os exemplos de código nesta página estão sujeitos às licenças descritas na Licença de conteúdo. Java e OpenJDK são marcas registradas da Oracle e/ou suas afiliadas.
Última atualização 2025-07-27 UTC.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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)"]]