How to access http
resource from https
served app?
#506
Replies: 4 comments
-
Beta Was this translation helpful? Give feedback.
-
For some reason, iOS allows any HTTP and HTTPS requests from an application served from the |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
There are two network stacks at play: 1) Native network stack, and 2) The webview network stack. The webview network stack does use the native network stack, so policies that apply to the native network stack also applies to webview networking. However the webview network stack may apply additional policies that affects the behaviour of the web app. By default android blocks plaintext (insecure) network traffic at the native network stack level. Webview may have additional policies, like blocking network insecure traffic when the document origin is Native Network StackTo address the native stack, you don't need to broadly allow plaintext traffic, you can use a network policy to isolate it to a specific domain. So instead of: <!-- config.xml -->
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config> You can do this instead: <!-- config.xml -->
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:networkSecurityConfig="@xml/network_security_config"
</edit-config> This points android to a <!-- network_security_config.xml -->
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain includeSubdomains="true">secure.example.com</domain>
</domain-config>
</network-security-config> And then finally, we can add another line inside <!-- config.xml -->
<resource-file src="network_security_config.xml" target="res/xml/network_security_config.xml" /> More information on the android's security config can read at https://developer.android.com/privacy-and-security/security-config Webview network stackAdjusting the native network policies might not be enough. By default android apps are hosted through WebViewAssetLoader and is configured on the Therefore the following might be necessary: <!-- config.xml -->
<preference name="scheme" value="http" /> Which will turn the hosted container into a |
Beta Was this translation helpful? Give feedback.
-
The question is which is the proper way to access
http
resource fromhttps
served app?Solution 1
When the app is served from
http
:It is possible to bypass any restriction by adding the following config:
But it seems that this is the least secure method of all.
Solution 2
cordova-plugin-ionic-webview
plugin allows to specify:Android documentation: https://developer.android.com/reference/android/webkit/WebSettings#setMixedContentMode(int)
This allows access to any
http
domains from the application.Questions
cordova-android
implements the ability to setsetMixedContentMode
setting?Beta Was this translation helpful? Give feedback.
All reactions