Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions android/app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<network-security-config xmlns:tools="http://schemas.android.com/tools">
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
<certificates src="user"
tools:ignore="AcceptsUserCertificates" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grahamsmith Why do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Android Studio's linter highlights this as a security risk and so the ignore tells it not to worry.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

</trust-anchors>
</base-config>
<debug-overrides>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it's not working.
You can try running your app on your device with: npx react-native run-android --variant=playDebug
You're going to get this screen:

That's because the JS bundle is sent to the device via port 8081 and it needs cleartextTrafficPermitted="true".
Apparently, <debug-overrides> isn't really doing anything.
If I got it right, <debug-overrides> can't contain a <base-config>: https://developer.android.com/training/articles/security-config#debug-overrides

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a look - I forgot about how RN debugging works as I tried with a production build. 👍

<base-config cleartextTrafficPermitted="true" >
<trust-anchors>
<certificates src="user" />
<certificates src="system" />
</trust-anchors>
</base-config>
</debug-overrides>
</network-security-config>