[Android] Security Settings for Official APK Releases

When preparing an APK for release, configure these common security settings:

1. Do not set debugable=true
Before disabling it:
ss2
After disabling it:
ss1

1) Project -> Build Automatically (uncheck Build Automatically)
2) Project -> Clean
3) Project -> Build
4) Android Tools -> Export Android application

2. Disable allowBackup:
Edit AndroidManifest.xml and add the following attribute to the application tag and each activity tag:

android:allowBackup="false"

3. Check the risks of exposing BroadcastReceiver components
Consider the following scenarios:

1) The component does not need to be exposed
If communication takes place only within the app, use a private receiver. Add the following attribute to the component in AndroidManifest.xml:

android:exported="false"

This receiver can receive messages from components in the same app or from apps that share the same user ID.

2) The component needs to be exposed
There are two cases:

2.1) Expose it only to your own apps or other apps from the same company
Option A:
Add the following attribute to the component in AndroidManifest.xml:

android:protectionLevel="signature"

Then require this permission on the component being called:

Option B:
In the component’s implementation, use Context.checkCallingPermission() to check whether the caller has the required permission.

2.2) The component must be exposed to third-party apps
Review the component’s code carefully to make sure its behavior stays within intended limits and to prevent risks such as capability leaks or permission redelegation (where an attacker gains additional permissions). Strictly validate all external input parameters to prevent null object references from causing a denial of service.

Additional security recommendations for dynamically registered components:
Use LocalBroadcastManager to register the receiver.
Use registerReceiver(BroadcastReceiver, IntentFilter, permission, Handler) instead of registerReceiver(BroadcastReceiver, IntentFilter), and make sure the private permission is enforced through signature verification.

Add a Comment

Your email address will not be published. Required fields are marked *