RUScan

Learn / Android hardening

Cleartext traffic in Android: how to turn it off and verify the fix

What usesCleartextTraffic does, how to replace it with a network security config, which command proves the flag is gone from the release build, and when an exception for one host is justified.

Updated: 2026-11-24·6 min read

The report line looks like this: Cleartext traffic allowed, category transport, severity medium. APKSonar raises it when the manifest of the package carries android:usesCleartextTraffic="true". With this flag the app is allowed to send data over plain HTTP, where anyone on the network path can read and alter it. Here is what the flag does, how to remove it and how to prove the fix in the release build.

What the flag does

The Android documentation defines the attribute like this: it "indicates whether the app intends to use cleartext network traffic, such as cleartext HTTP". The default is true for apps that target API level 27 or lower and false for apps that target API level 28 or higher. Two more notes from the same page matter for the fix. The attribute is getting deprecated and will be ignored for apps targeting API level 38 and above. And it is ignored on Android 7.0 and higher as soon as the app has a network security config.

How it gets into a release build

  • Someone switched it on to reach an http:// test server and it stayed.
  • A library or an old project template ships it in its own manifest, and the manifest merger keeps it.
  • Debug and release builds share one manifest, with no override for the release variant.

The fix: a network security config

The current mechanism is a network security config. It states the policy in one XML file.

Step 1. Create res/xml/network_security_config.xml. This is the default policy for apps targeting Android 9 and higher, written out:

<network-security-config>
    <base-config cleartextTrafficPermitted="false">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
</network-security-config>

Step 2. Reference the file on the application element of AndroidManifest.xml:

<application
    android:networkSecurityConfig="@xml/network_security_config"
    ... >

Step 3. Delete android:usesCleartextTraffic="true" from the same element.

Step 4. Move the remaining http:// endpoints to https://. After the change a cleartext request fails with an error.

One legacy host that still needs HTTP

Sometimes a partner server has no TLS yet. Allow that one host and nothing else:

<domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="false">legacy.example.com</domain>
</domain-config>

Put the block in the same file. Each such domain is a documented exception. Give it an owner and a removal date, otherwise it outlives the partner server.

Verify the fix

Decode the manifest of the built APK and look for the attribute:

jadx -s -d out app.apk
grep -n "usesCleartextTraffic\|networkSecurityConfig" \
  out/resources/AndroidManifest.xml

The flag -s skips the sources, so the run takes seconds. The expected result is no line with usesCleartextTraffic="true". The same check exists in the SDK: apkanalyzer manifest print app.apk prints the manifest in XML format, and the output goes through the same grep.

The last check is the scan itself. Upload the fixed build and the report no longer lists "Cleartext traffic allowed".

Keep it fixed in CI

A regression here costs one merge. Add one line to the release pipeline, after the build and before the upload to the store:

apkanalyzer manifest print app-release.apk \
  | grep -q 'usesCleartextTraffic="true"' \
  && { echo "cleartext flag in release manifest"; exit 1; }

The pipeline fails while the attribute is present and passes silently when it is gone. The same pattern works for the debuggable flag. A full scan in the pipeline goes further: it also catches leaked keys and outdated libraries.

Frequently asked

Will the app break after I remove the flag?

Only requests that go to plain http:// hosts. They start to fail with an IOException that names the network security policy. Move those endpoints to https:// or allow the one host that genuinely needs HTTP as a documented exception.

The manifest has no usesCleartextTraffic attribute and targetSdk is 27 or lower. Is traffic encrypted?

Not necessarily. By the documentation the default for apps targeting API level 27 or lower is true, so cleartext traffic is allowed unless a network security config forbids it. APKSonar reports the attribute when it is set to true explicitly. A network security config with cleartextTrafficPermitted=false closes the default as well.

The app only talks to https:// servers. Do I need the flag?

No. The attribute grants permission, it does not redirect anything. With https:// endpoints everywhere the flag is dead weight that weakens the defaults: remove it.

How serious is the finding?

APKSonar rates it medium. The flag permits unencrypted traffic. It becomes real damage the moment any request carries a token or personal data over HTTP, because anyone on the network path can read and change it.

More on this topic

From other categories

All articles →