TExcelTAD
Home › Wireless, IoT & Mobile Security › Android Manifest Review: Exported Components, Debuggable, Cleartext

Android Manifest Review: Exported Components, Debuggable, Cleartext

Every Android app carries a file that declares, before a line of its code runs, how it can be reached and what it is allowed to do: AndroidManifest.xml. A reviewer can read it from any APK in seconds (Android Studio's APK Analyzer, apktool, aapt2 dump, inspecting APKs), and so can an attacker. Three classes of manifest mistakes appear in app after app: exported components that any other app on the phone can call, a debuggable release, and cleartext traffic allowed by the app or its network security configuration. This lesson builds a checker for all three on the course's sample app and shows the fixed manifest.

Components and "exported"

An app consists of activities (screens), services (background work), broadcast receivers (event handlers) and content providers (data shared through content:// URIs). A component with android:exported="true" can be started by any app on the device, with any data the caller chooses, unless it requires a permission that callers must hold. Since Android 12 (target SDK 31) every component with an intent filter must say exported explicitly; before that, an intent filter silently meant exported.

What goes wrong when an internal component is exported:

  • an activity that skips the login screen ("DeviceAdminActivity") opens for any app, with the user's session;
  • a receiver that executes commands ("CommandReceiver: relay off") obeys any app's broadcast;
  • a provider returns the user's device list, or with path-traversal bugs arbitrary files from the app's sandbox;
  • a service guarded by a custom permission whose protectionLevel is normal is guarded by nothing: any app can request a normal permission and gets it without asking the user. Use signature for permissions meant only for your own apps.

Deep-link activities (BROWSABLE with a URL scheme) must be exported, because browsers and other apps open them. Their risk is the input: every parameter of labhome://pair?... comes from an untrusted source.

Debuggable and backups

  • android:debuggable="true" lets anyone with USB debugging attach a debugger, run code as the app with run-as and read its private files. The build system sets it for debug builds only; a hard-coded true in the manifest leaks into releases. Release builds must never be debuggable.
  • android:allowBackup="true" (the default) includes app data in device backups and device-to-device transfers. For apps with tokens and keys, either turn it off or define exactly what may be backed up (android:dataExtractionRules on Android 12+, fullBackupContent before), excluding secrets; keys in the Keystore are never backed up anyway.

Cleartext traffic

Since Android 9 (target SDK 28), cleartext HTTP is blocked by default. Apps re-enable it in two places: android:usesCleartextTraffic="true" on the application, or a cleartextTrafficPermitted="true" in the Network Security Configuration file (res/xml/network_security_config.xml), which takes precedence when present. The same file decides which CAs the app trusts: system CAs only in release builds, user-installed CAs only inside <debug-overrides> (so testers can intercept debug builds), and optionally pins (Certificate Pinning).

The checker

The sample app's manifest and network configuration (synthetic, in source form; a decoded APK gives the same XML), and a checker for the rules above, using xml.etree.ElementTree with the Android namespace:

python · try it yourself
import xml.etree.ElementTree as ET

MANIFEST = """<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test.lab.labhome">
  <uses-sdk android:minSdkVersion="26" android:targetSdkVersion="35"/>
  <application android:label="LabHome" android:debuggable="true" android:allowBackup="true"
               android:usesCleartextTraffic="true" android:networkSecurityConfig="@xml/network_security_config">
    <activity android:name=".MainActivity" android:exported="true">
      <intent-filter><action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/></intent-filter>
    </activity>
    <activity android:name=".DeviceAdminActivity" android:exported="true"/>
    <activity android:name=".PairingLinkActivity" android:exported="true">
      <intent-filter><action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="labhome" android:host="pair"/></intent-filter>
    </activity>
    <service android:name=".SyncService" android:exported="true" android:permission="test.lab.labhome.SYNC"/>
    <receiver android:name=".CommandReceiver" android:exported="true"/>
    <provider android:name=".DeviceProvider" android:authorities="test.lab.labhome.devices" android:exported="true"/>
  </application>
  <permission android:name="test.lab.labhome.SYNC" android:protectionLevel="normal"/>
</manifest>"""

NSC = """<network-security-config>
  <base-config cleartextTrafficPermitted="false">
    <trust-anchors><certificates src="system"/><certificates src="user"/></trust-anchors>
  </base-config>
  <domain-config cleartextTrafficPermitted="true"><domain includeSubdomains="true">api.lab.test</domain></domain-config>
  <debug-overrides><trust-anchors><certificates src="user"/></trust-anchors></debug-overrides>
</network-security-config>"""

A = "{http://schemas.android.com/apk/res/android}"
root = ET.fromstring(MANIFEST)
app = root.find("application")
perm_levels = {p.get(A + "name"): p.get(A + "protectionLevel", "normal") for p in root.findall("permission")}
findings = []
if app.get(A + "debuggable") == "true":
    findings.append(("HIGH", "application", "debuggable=true: any user with adb can attach a debugger and read app data"))
if app.get(A + "allowBackup", "true") == "true":
    findings.append(("MED", "application", "allowBackup=true without backup rules: app data goes into device backups"))
if app.get(A + "usesCleartextTraffic") == "true":
    findings.append(("HIGH", "application", "usesCleartextTraffic=true: plain HTTP allowed"))
for kind in ("activity", "service", "receiver", "provider"):
    for c in app.findall(kind):
        name, exported = c.get(A + "name"), c.get(A + "exported")
        cats = {x.get(A + "name").rsplit(".", 1)[1] for x in c.findall(".//category")}
        if exported != "true" or "LAUNCHER" in cats:
            continue
        perm = c.get(A + "permission")
        if "BROWSABLE" in cats:                    # deep links must be reachable from browsers
            d = c.find("intent-filter/data")
            findings.append(("INFO", f"{kind} {name}", f"deep link {d.get(A + 'scheme')}://{d.get(A + 'host')}: "
                             "treat every parameter as untrusted input"))
        elif perm is None:
            findings.append(("HIGH", f"{kind} {name}", "exported without a permission: any app can call it"))
        elif perm_levels.get(perm, "?") == "normal":
            findings.append(("HIGH", f"{kind} {name}", f"protected by {perm}, but its protectionLevel is normal: any app can hold it"))
nsc = ET.fromstring(NSC)
for dc in nsc.findall("domain-config"):
    if dc.get("cleartextTrafficPermitted") == "true":
        findings.append(("HIGH", "network config", f"cleartext allowed for {', '.join(d.text for d in dc.findall('domain'))}"))
for bc in nsc.findall("base-config"):
    if bc.find("trust-anchors/certificates[@src='user']") is not None:
        findings.append(("HIGH", "network config", "release build trusts user-installed CAs: whoever gets a CA onto the device can intercept"))
for sev, where, text in findings:
    print(f"{sev:4} {where:32} {text}")
HIGH application                      debuggable=true: any user with adb can attach a debugger and read app data
MED  application                      allowBackup=true without backup rules: app data goes into device backups
HIGH application                      usesCleartextTraffic=true: plain HTTP allowed
HIGH activity .DeviceAdminActivity    exported without a permission: any app can call it
INFO activity .PairingLinkActivity    deep link labhome://pair: treat every parameter as untrusted input
HIGH service .SyncService             protected by test.lab.labhome.SYNC, but its protectionLevel is normal: any app can hold it
HIGH receiver .CommandReceiver        exported without a permission: any app can call it
HIGH provider .DeviceProvider         exported without a permission: any app can call it
HIGH network config                   cleartext allowed for api.lab.test
HIGH network config                   release build trusts user-installed CAs: whoever gets a CA onto the device can intercept

Ten findings, eight of them high. Only the launcher activity and the deep link are exported by design. The two network findings undo the platform's defaults for the app's own API and for every connection: with user CAs trusted in release, anyone who can get a certificate installed (a malicious "Wi-Fi profile", a work-profile CA, a curious user) can read and change all traffic.

The fixed manifest

xml
<application android:label="LabHome" android:allowBackup="false"
             android:networkSecurityConfig="@xml/network_security_config">
  <activity android:name=".MainActivity" android:exported="true"> <!-- launcher --> </activity>
  <activity android:name=".DeviceAdminActivity" android:exported="false"/>
  <activity android:name=".PairingLinkActivity" android:exported="true"> <!-- deep link; validates input --> </activity>
  <service android:name=".SyncService" android:exported="false"/>
  <receiver android:name=".CommandReceiver" android:exported="false"/>
  <provider android:name=".DeviceProvider" android:authorities="test.lab.labhome.devices" android:exported="false"/>
</application>
<!-- if another app of the same developer must call SyncService: protectionLevel="signature" -->
xml
<network-security-config>
  <base-config cleartextTrafficPermitted="false">
    <trust-anchors><certificates src="system"/></trust-anchors>
  </base-config>
  <debug-overrides><trust-anchors><certificates src="user"/></trust-anchors></debug-overrides>
</network-security-config>

No debuggable attribute (the build type decides), no usesCleartextTraffic, components private unless they must be public.

How these flaws are detected

  • In CI: Android Lint flags hard-coded debuggable, missing exported, cleartext and insecure network configurations; a checker like the one above runs on the merged manifest of the release build (manifest merger: libraries can add components and permissions you never wrote).
  • Static analysis tools such as MobSF report the same items from a built APK (mobile app testing).
  • Dynamic tests on a test device: try to start each exported component from another app or with adb shell am start / am broadcast / content query, and check that it refuses.

How they are fixed

  • exported="false" for everything internal; signature-level permissions for components shared between your own apps; strict input validation in deep-link and other public entry points.
  • Never ship debuggable releases; let the build type set it.
  • allowBackup="false" or explicit backup rules that exclude secrets; secrets in the Keystore.
  • Cleartext off everywhere; user CAs only in debug-overrides.

Pitfalls

  • Fixing the source manifest but not checking the merged one: a library's manifest can export a component.
  • Protecting a component with a custom permission at normal level.
  • Leaving usesCleartextTraffic="true" because "the network config already says false": remove the confusion; keep one source of truth.

Practice

1. Change .CommandReceiver to android:exported="true" android:permission="test.lab.labhome.SYNC". What does the checker say, and what is the real fix?

It reports that the receiver is protected by a permission with normal protection level, which any app can hold. The real fix is exported="false", or a signature-level permission if another app of the same developer must send it commands.

2. Why is the pairing deep link reported as INFO rather than HIGH?

A browsable deep link has to be exported so that browsers and QR-code scanners can open it. Its risk is in the parameters, which the activity must validate: for example, accept only a well-formed pairing code and never a URL to load or a command to run.

3. A tester asks to keep <certificates src="user"/> in release "for our proxy tests". What do you propose?

Put it inside <debug-overrides>, which applies only to debuggable builds, and test with debug builds. Release builds must trust only system CAs (plus pins where used).

Test yourself

Who can start an activity declared with android:exported="true" and no permission?

  1. Only the app itself
  2. Any app on the device
  3. Only system apps
  4. Only apps from the same developer

Why doesn't a custom permission with protectionLevel="normal" protect a service?

  1. Normal permissions are always denied
  2. Any app can request a normal permission and gets it without user approval
  3. It only works on iOS
  4. It encrypts the service

Where should a release build allow trust in user-installed CAs?

  1. In base-config
  2. Nowhere; only inside debug-overrides for debug builds
  3. In domain-config for the API
  4. In the manifest

What is the risk of a release build with android:debuggable="true"?

  1. Slower startup
  2. A debugger can attach and run-as can read the app's private data
  3. No risk
  4. The app can't be installed