How to Limit PendingIntent Permissions for an Android Notification Button
A notification button should have a clear purpose: what action it performs and whether that action may be repeated. When configuring PendingIntent, describe these constraints explicitly. We’ll cover which fields to check, when to use FLAG_IMMUTABLE and FLAG_ONE_SHOT, and how to assess changes in your own app. The example below is entirely fictional; verification uses only builds and test data owned by the team.
Where the Trust Boundary Lies
PendingIntent is a reference to a token maintained by the system. A receiving app’s ability to update the underlying Intent according to the fillIn() rules applies specifically to a mutable PendingIntent. Before choosing flags, developers therefore need to determine whether the recipient needs to add anything to the action description at all.
The trust boundary lies between the action defined by the app and the changes the recipient can make. The documentation warns that a malicious app can modify unspecified fields, potentially allowing access to non-exported components. When reviewing a button, check the specific fields and whether mutability is necessary, rather than simply checking that a PendingIntent exists.
Fictional Example: An “Open Request” Button
Imagine a fictional app called Workshop with an “Open Request” notification button. For this learning exercise, the team creates its own request containing fictional data. The team records the expected behavior in advance: the button should perform the agreed action in the app, and the recipient does not need to add anything to the description of that action.
The team separately decides whether repeated execution is allowed. The button’s label alone does not determine this. In this example, reopening the request is expected behavior. A different operation intended to run once would have different requirements. This distinction helps the team choose constraints based on the product’s needs instead of applying the same set of flags to every notification.
Specify the Action and Recipient Explicitly
The documentation recommends setting action, component and package to limit PendingIntent risks. For the example button, make these three fields a required check wherever the underlying Intent is created. Compare each value with the button’s agreed purpose: which action is intended, which component is specified and which package is selected.
The practical fix is to populate missing fields and check existing values. In the change description, state which fields were previously unspecified and what is now explicitly set. This makes the fix verifiable by another developer. Do not treat the presence of one of the three fields as sufficient grounds to close the entire review item.
Separate Immutability from Single Use
FLAG_IMMUTABLE prevents a malicious third-party app from filling in unspecified fields. If the button’s requirements do not call for the recipient to supplement the Intent, use this flag to restrict that ability. Continue checking action, component and package: the documentation describes explicitly populating fields and immutability as separate measures.
For a PendingIntent that should not run multiple times, the documentation recommends FLAG_ONE_SHOT to prevent reuse. Choose it according to the requirement for the number of executions. In the fictional example, reopening is allowed, so the stated requirements provide no reason to require single use. For an operation intended to run once, include this flag in the list of fixes and verify repeated execution separately.
Verify the Result in Your Own Test Build
Start by reviewing how the PendingIntent is created: record the values of the three fields, the selected flags and the corresponding requirements. Then use your own test build to check a normal button tap on the fictional request. Record the expected and actual action so you can assess the result against the condition established in advance.
If FLAG_ONE_SHOT is used, separately test a second execution of the same PendingIntent. Test restrictions on modifications only in a controlled test run by your team, without interacting with other parties’ apps or data. A successful normal tap does not verify every stated constraint: each requirement needs a separate result. Keep the test conditions alongside the fix description.
Set Priorities and Review Related Requirements
First, address unspecified action, component and package fields and whether mutability is necessary. Then compare FLAG_ONE_SHOT with the requirement for repeated execution. This order lets you clarify the boundaries of the button’s action before checking restrictions on its use. Close each item with a specific change or a justified decision based on the requirements.
Review permissions separately: the app should request only the minimum permissions necessary to operate. If the scenario involves requesting credentials to access sensitive information, the documentation recommends a PIN, password, pattern or biometric credentials. Include these questions in the review of the relevant scenario while keeping a separate check of the PendingIntent configuration.
Account for the Review’s Limits and the Next Step
This review covers the listed PendingIntent settings, permission minimization and the recommendation for requesting credentials. It provides no basis for declaring the entire app secure. In the review results, specify which buttons and requirements were examined, which tests were performed and what remained outside the review.
If the product has a website or web component, you can start with a free audit of that website or web product. Its results apply to the web scope examined; verification of the Android notification-button scenario should be accounted for separately.