How to Restrict Incoming Content URIs and Exclude Your Own Provider
An incoming content URI is not, by itself, a reason to read the resource it identifies. For a narrowly scoped Android integration, define acceptable sources in advance and validate the URI before calling ContentResolver. Excluding your own internal provider is a separate requirement: an externally supplied link must not cause the app to read its own internal content. We will outline a validation contract and a fully fictional example using test apps and synthetic documents controlled by the team.
Where the Trust Boundary Lies
In the file-sharing scenario described in the documentation, a server app returns a content URI to a client inside an Intent. The client must decide whether that source is acceptable for the specific operation. The trust boundary lies between receiving the external URI and opening the resource it identifies: validation belongs here, and its result must determine whether reading proceeds.
The documentation identifies two risks: an app processes its own internal content through an externally supplied link, or it acts as an intermediary for accessing another app’s data. Deciding that a link looks as expected is therefore insufficient. An explicit list of allowed authorities and an independent check of whether the provider belongs to the current app are required.
Allow Expected Sources and Independently Reject Your Own Provider
For incoming URIs, the documentation recommends validation, including an allowlist of expected authorities. Define a finite list for a single integration: exactly which sources it should accept. The documentation considers maintaining a list of prohibited values an error-prone approach.
Keep the two checks separate. Matching the authority against the allowlist determines whether the integration contract permits that source. To establish whether a provider belongs to the current app, the documented example uses resolveContentProvider and compares the resolved provider’s package name with the app’s package name. This is an independent reason for rejection, even if an internal authority was mistakenly included in the allowlist.
The following is an original editorial contract, not an official Android procedure: accept only the content scheme and an exact authority match against the allowlist, then establish whether the provider belongs to the app. A missing authority, inability to establish ownership, or matching package names means rejection before the resource is opened.
A Fully Fictional Example of a Narrowly Scoped Integration
Imagine a client test app and two external test apps, all controlled by your team. The first provides a synthetic document through the authority example.allowed.documents, and the second through example.other.documents. The client’s internal provider has the authority example.client.internal. Every name, app, and document in this example is fictional and controlled by the team.
Only example.allowed.documents is included in the allowlist. The expected document contains the predefined bytes TEST-DOCUMENT-42. The necessary permissions are arranged in advance for the positive scenario. URI validation selects an acceptable source but does not grant permissions: in the documented scenario, the client receives access only within the permissions granted by the server app.
How to Observe Acceptance and Rejection Before Reading
The following checks are original editorial tests using data you control. Put resource opening behind a controlled wrapper with a call counter, and record the event order: validation, decision, opening, and read result. The openFileDescriptor method returns a ParcelFileDescriptor; the FileDescriptor obtained from it is used for reading. A success or rejection message alone is insufficient: you need to observe whether opening occurred and which bytes were read.
- Positive control: the allowed external provider passes validation; the resource is then opened for reading, and the returned bytes exactly match TEST-DOCUMENT-42.
- Unknown source: a URI with example.other.documents is rejected; the opening counter remains at zero.
- Your own provider: a URI with example.client.internal is rejected before opening. In a separate test configuration, add this authority to the allowlist and repeat the check: the package comparison must still result in rejection, with the counter at zero.
- Contract boundaries: URIs without an authority, with a different scheme, or with an authority that merely resembles the allowed one are rejected without calling the opening operation.
What to Fix First
The first priority is to decide whether a URI is acceptable before opening the resource. If a negative test shows even one opening call, the fix does not yet satisfy the agreed contract, even if the interface reports rejection. Check every read operation within this narrowly scoped integration: each must depend on the validation result.
Next, establish a finite list of authorities and an independent rejection check for your own provider. Accidentally adding an internal authority to the allowlist must not bypass the package comparison. After making changes, repeat the negative scenarios and the positive control: prohibited sources are not opened, while the allowed source returns the expected bytes when the necessary permissions are present. These are concrete completion criteria for the developer and product owner.
Limits of the Results and the Next Step
Passing these tests confirms the observable source-selection contract in this integration. It does not prove that the content is safe, confirm that the necessary permissions are present, or provide a statistical guarantee of security. Selection by DISPLAY_NAME, saving a local copy, FileProvider configuration, granting URI permissions, file path validation, and archive extraction are outside this article’s scope.
Record the allowed authorities and expected validation outcomes as integration requirements. If your product has a website or web component, CheckMyApp offers a free audit of it. That offer covers the web product; the team performs the Android integration checks described here separately, using its own test apps and synthetic documents.