Repository navigation
fix(cli): apply cleartext to the app module and merge with existing network-security-config - #8671
Merged
Merged
Conversation
…etwork-security-config Cleartext opt-in was written to the generated capacitor-cordova-android-plugins module, which is not linked into Capacitor-only apps and conflicts with an app-owned network-security-config.xml. Write it to android/app instead, merging only cleartextTrafficPermitted and tracking CLI changes with a marker comment so they can be reverted without touching app-owned content. ref: RMET-5420
alexgerardojacinto
requested review from
ItsChaceD,
OS-ruimoreiramendes,
andredestro,
jcesarmobile,
markemer and
theproducer
October 21, 2026 20:22
OS-ruimoreiramendes
approved these changes
Oct 22, 2026
OS-ruimoreiramendes
left a comment
Contributor
There was a problem hiding this comment.
Tested locally with the inappbrowser example app.
- Capacitor-only app, no NSC:
server.cleartexton → NSC + manifest ref created, HTTP loads; off → both removed - App with own NSC (same name), with
<base-config>=false+ trust-anchors +<domain-config>with a pin: only<base-config>flipped, everything else untouched, revert byte-equal to original. - App with own NSC under a different name (
my_nsc.xml): no parallel file created, manifest untouched, build no longer breaks on the manifest merger cap run: create/revert NSC + manifest.
LGTM 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #8572. Applies cleartext opt-in (
server.cleartext, live-reload, Cordovaedit-configusesCleartextTraffic) to the app module instead of the generatedcapacitor-cordova-android-pluginsmodule, and merges into an existingnetwork-security-config.xmlinstead of competing with it.android/app/src/main/res/xml/and referenced fromandroid/app/src/main/AndroidManifest.xml.cleartextTrafficPermittedon<base-config>is changed (the element is added if missing). Trust anchors, pinning and<domain-config>entries are left untouched, so a<domain-config>that blocks cleartext for a host still applies to that host.<!-- capacitor:cleartext ... -->marker comment in the config file records what the CLI did (created the file, added the manifest reference, original<base-config>value), so turning the trigger off reverts only the CLI's own changes: a created file is deleted, an edited file gets its original value back, and an app-owned file or reference is never deleted.cap run --urlthat fails now reverts the cleartext configuration too (previously only the cap config was reverted).server.cleartextJSDoc updated.ref: RMET-5420
Change Type
Rationale / Problems Fixed
Since #8572, on Capacitor 9 the plugins module is only linked into the app when it has at least one Cordova plugin:
server.cleartext=truewas a silent no-op.network-security-config.xml: with the same filename the app's file won the manifest merge (the CLI's value was silently overridden); with a different filename the manifest merger failed onandroid:networkSecurityConfig, andtools:replaceunblocked the build but the app's file still won.Tests or Reproductions
Unit tests:
cli/test/android-cleartext.spec.ts(merge/revert/idempotency, own config with same/different name, legacy file cleanup) andcli/test/run-cleartext-revert.spec.ts(failedcap run --url). Full CLI suite passes (22 suites).Control, same scratch app built with the CLI before and after this change,
server.cleartext=true:Suggestion: add 'tools:replace="android:networkSecurityConfig"'<base-config>truecleartextTrafficPermitted="false"<base-config>true, restored on revertRuntime, on a Pixel 7 (Android 17) and a Pixel 3 XL (Android 12) with the same results on both. A test page fetches
http://httpforever.com/andhttps://example.com/throughCapacitorHttp:server.cleartext=falseserver.cleartext=truefalse<base-config>false),false/true/false<domain-config httpforever.com cleartext=false>,trueexample.com,true/falsecap run --url http://localhost:8080 --forwardPorts 8080:8080,server.cleartext=falsePlatforms Affected