Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/allow mixed content #1867

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't appear we actually need this here since we're setting it in <network-security-config> in react_native_config.xml

<application tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>
13 changes: 8 additions & 5 deletions android/app/src/main/java/io/metamask/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.metamask.nativeModules.PreventScreenshotPackage;

import androidx.multidex.MultiDexApplication;
import android.webkit.WebView;


public class MainApplication extends MultiDexApplication implements ShareApplication, ReactApplication {
Expand Down Expand Up @@ -53,12 +54,14 @@ public ReactNativeHost getReactNativeHost() {

@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);

initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
RNBranchModule.getAutoInstance(this);
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);

initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
RNBranchModule.getAutoInstance(this);
if (BuildConfig.DEBUG) {
WebView.setWebContentsDebuggingEnabled(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is needed to debug the WebView for android

}
}
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext
}

@Override
public List<NativeModule> createNativeModules(
ReactApplicationContext reactContext) {
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();

modules.add(new RCTAnalytics(reactContext));
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/xml/react_native_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
<domain includeSubdomains="false">10.0.2.2</domain>
<domain includeSubdomains="false">10.0.3.2</domain>
</domain-config>
<base-config cleartextTrafficPermitted="false" />
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
3 changes: 2 additions & 1 deletion app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,8 @@ export const BrowserTab = props => {
javascriptEnabled
allowsInlineMediaPlayback
useWebkit
testID={'browser-webview'}
testID="browser-webview"
mixedContentMode="compatibility"
/>
)}
</View>
Expand Down
7 changes: 4 additions & 3 deletions app/util/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import URL from 'url-parse';
import isUrl from 'is-url';

/**
* Returns a sanitized url, which could be a search engine url if
Expand All @@ -11,8 +12,8 @@ import URL from 'url-parse';
*/
export default function onUrlSubmit(input, searchEngine = 'Google', defaultProtocol = 'https://') {
//Check if it's a url or a keyword
const res = input.match(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!&',;=.+]+$/g);
if (res === null) {
const regEx = new RegExp(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!&',;=.+]+$/g);
if (!isUrl(input) && !regEx.test(input)) {
// Add exception for localhost
if (!input.startsWith('http://localhost') && !input.startsWith('localhost')) {
// In case of keywords we default to google search
Expand All @@ -23,7 +24,7 @@ export default function onUrlSubmit(input, searchEngine = 'Google', defaultProto
return searchUrl;
}
}
const hasProtocol = input.match(/^[a-z]*:\/\//);
const hasProtocol = /^[a-z]*:\/\//.test(input);
const sanitizedURL = hasProtocol ? input : `${defaultProtocol}${input}`;
return sanitizedURL;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"events": "3.0.0",
"fuse.js": "3.4.4",
"https-browserify": "0.0.1",
"is-url": "^1.2.4",
"json-rpc-engine": "5.1.5",
"json-rpc-middleware-stream": "2.1.1",
"lottie-react-native": "git+https://github.com/MetaMask/lottie-react-native.git#7ce6a78ac4ac7b9891bc513cb3f12f8b9c9d9106",
Expand All @@ -128,7 +129,7 @@
"react-native": "0.62.2",
"react-native-actionsheet": "beefe/react-native-actionsheet#107/head",
"react-native-aes-crypto": "^1.3.9",
"react-native-aes-crypto-forked": "git+https://github.com/MetaMask/react-native-aes-crypto-forked.git#397d5db5250e8e7408294807965b5b9fd4ca6a25",
"react-native-aes-crypto-forked": "git+https://github.com/MetaMask/react-native-aes-crypto-forked.git#397d5db5250e8e7408294807965b5b9fd4ca6a25",
"react-native-animated-fox": "git+https://github.com/MetaMask/react-native-animated-fox.git#16e38d54d829709e497f196e31fa8ff00cdf2aa9",
"react-native-background-timer": "2.1.1",
"react-native-branch": "5.0.0-beta.1",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6961,6 +6961,11 @@ [email protected], is-typedarray@^1.0.0, is-typedarray@~1.0.0:
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=

is-url@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/is-url/-/is-url-1.2.4.tgz#04a4df46d28c4cff3d73d01ff06abeb318a1aa52"
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==

is-weakmap@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.1.tgz#5008b59bdc43b698201d18f62b37b2ca243e8cf2"
Expand Down