ContentProvider class provides a mechanism for managing and sharing data with other applications. When sharing a provider’s data with other apps, access control should be carefully implemented to prohibit unauthorized access to sensitive data.
There are three ways to limit access to the content provider:
- Restricted access
By specifying the
android:exported attribute in the AndroidManifest.xml file, a content provider is made public to other applications. For Android applications before API Level 16, a content provider is public unless explicitly specified
android:exported="false". For example,
If a content provider is to be made public, the data stored in a provider may be accessed from other applications. Therefore, it should be designed to handle only nonsensitive information.
You can make your provider private by specifying the
android:exported attribute in the AndroidManifest.xml file. From API Level 17 and later, a content provider is private if you do not specify the attribute explicitly. For example,
If you do not need to share a content provider with other applications, it should be declared
android:exported="false" in the manifest file. Note, however, in API Level 8 and earlier, even if you explicitly declare
android:exported="false", your content provider is accessible from other apps.
<<@TODO: flesh out more details, write these rules.>>
Noncompliant Code Example
MovatwiTouch, a Twitter client application, used a content provider to manage Twitter’s consumer key, consumer secret, and access token. However, the content provider was made public, which enabled applications installed on users’ devices to access this sensitive information.
The following entry in the AndroidManifest.xml does not have the
android:exported attribute, which means, before API Level 16, the content provider is made public:
Proof of Concept
The following code shows how this could be exploited:
The following entry in the AndroidManifest.xml file makes the content provider private so that other apps cannot access the data:
Declaring a public content provider can leak sensitive information to malicious apps.
It is trivial to automatically detect when a content provider is declared public.
- JVN#90289505 Content provider in MovatwiTouch fails to restrict access permissions
4.3. Creating/using content providers