← All articlesMobile applications

Nested Intents in Android: Allow Only Intended Actions

A nested Intent from an external request should be handled according to the application’s rules, rather than accepted as a ready-made instruction to launch a component. The developer’s task is to define the permitted action, validate its destination and review the supplied data and access permissions. Android documentation recommends avoiding nested Intent redirection features altogether where possible. If the product requires this scenario, document its limits separately and verify them using your own test data.

First, Decide Whether Redirection Is Necessary

Start with the product scenario: what action should the user perform, and why does it require a nested Intent? If the redirection feature can be removed, doing so follows the documentation’s recommendation. Do not retain it solely for flexibility or possible future integrations. For team discussions, write down a specific outcome, such as opening the intended document preview screen.

If redirection is necessary, define the trust boundary. The external request proposes data and a destination, while the application decides whether they match the permitted scenario. A practical implementation rule is to allow the launch only after the required checks. The mere presence of a nested Intent must not replace the application’s decision about which action is permitted.

Validate the Destination and Sanitize Data

The documentation recommends sanitizing the supplied information and validating the Intent’s destination. Its example checks the expected package name and component class name before launch. When designing validation, specify both values for the intended scenario: ‘open something in our application’ is too vague to serve as a verifiable requirement.

IntentSanitizer can help sanitize Intent data and validate the destination. However, choosing a tool does not define the product’s rules: the team must still decide which data and destinations are permitted. Define in advance that an unsuitable request will not be launched. This connects implementation and verification to clear expected behavior.

Review URI Access Permissions Separately

Make URI permission grant flags a separate review item. The documentation lists four flags: FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION, FLAG_GRANT_PERSISTABLE_URI_PERMISSION and FLAG_GRANT_PREFIX_URI_PERMISSION. They cover read, write, persistable and prefix access. When handling a nested Intent, these flags must be checked or cleared.

For each permission, record whether the specific action requires it. For example, in a fictional test document preview scenario, the team might allow read access only. The remaining flags then need separate consideration, with an expected handling outcome defined for each. This is a design decision for the example, rather than a universal rule for every application.

Fictional Example: Previewing a Training Document

Imagine an entirely fictional application called ‘Training Archive.’ An external request proposes opening a document on a preview screen. For this scenario, the team has selected the package com.example.trainingarchive and the class com.example.trainingarchive.DocumentPreviewActivity in advance. All documents, URIs and applications in this example belong to the developer’s test environment and contain no user data.

Expected behavior can be described before validation is implemented: the application checks the package and class against the selected destination, sanitizes the supplied data and checks or clears the URI access flags. If the destination does not match the scenario, no launch occurs. This example helps the team discuss specific acceptance criteria without turning the handler into a general-purpose redirection mechanism.

Data Sharing and the Basis for Trust

When passing data between applications, the documentation recommends content:// URIs instead of file:// URIs; FileProvider helps meet this requirement. For sharing between two applications under your control, signature-based permissions are recommended. Consider these measures alongside nested Intent checks, keeping a separate requirement and expected outcome for each.

Do not treat a non-null getCallingActivity() result as a reliable basis for trusting a request: the documentation warns that a malicious application can supply null. During review, find places where the launch decision depends on this check and compare them with the rules for destination validation, data sanitization and access permission handling.

A Safe Verification Plan and Remediation Priorities

Verify the handler in your own test environment. Prepare an allowed request from the fictional scenario, then change the package, class and access flag set one at a time. Record the expected result for each variation in advance: launching the intended screen, declining to launch or clearing specific flags. Use only your own test documents and record the actual behavior.

The first priority is to remove unnecessary redirection. If it is required, the next step is destination validation and data sanitization, followed by explicit handling of all four URI access flags. Then check the chosen URI sharing method and, for two applications you own, the use of signature-based permissions. Repeat the scenarios after the fixes to verify the agreed requirements.

Protection Limits and the Next Step

Android 16 introduces protection against Intent redirection exploitation that is enabled by default. The documentation recommends disabling launch protection cautiously and only when strictly necessary, because doing so may increase the risk of vulnerabilities. If disabling it is being considered, first examine the required product behavior and the results of your own checks.

This plan verifies the selected scenario and does not guarantee the security of the entire application. Keep the list of permitted actions, data handling rules and test results as a basis for further review. If the product has a website or web component, you can start with a free website or web-product audit from CheckMyApp; its findings apply to the web scope that was assessed.

Sources and documentation

  1. Intent redirection
  2. Security best practices
CheckMyApp

Check your application’s security.

Enter your web application address and email. Get a free preliminary report and choose the depth of analysis.

Check for free