From f3916edc42838fc8bcecf3caa5630788a484f249 Mon Sep 17 00:00:00 2001 From: rickycodes Date: Wed, 30 Sep 2020 16:13:41 -0400 Subject: [PATCH 1/3] Add additional isUrl check, closes #1462 --- app/util/browser.js | 7 ++++--- package.json | 3 ++- yarn.lock | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/util/browser.js b/app/util/browser.js index eef950409c2..861d736e7f3 100644 --- a/app/util/browser.js +++ b/app/util/browser.js @@ -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 @@ -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 @@ -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; } diff --git a/package.json b/package.json index b996eaee948..e5e57aa4133 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/yarn.lock b/yarn.lock index 8cb80320fe3..b801f34978b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6961,6 +6961,11 @@ is-typedarray@1.0.0, 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" From 36df6bdfa54c1ff50d6535d44b6395d7d521b00e Mon Sep 17 00:00:00 2001 From: rickycodes Date: Thu, 1 Oct 2020 12:56:03 -0400 Subject: [PATCH 2/3] Allow for mixed content in web views --- android/app/src/debug/AndroidManifest.xml | 2 +- .../src/main/java/io/metamask/MainApplication.java | 11 ++++++----- android/app/src/main/res/xml/react_native_config.xml | 2 +- app/components/Views/BrowserTab/index.js | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index fa26aa56e1c..7b0ed9b2833 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -4,5 +4,5 @@ - + diff --git a/android/app/src/main/java/io/metamask/MainApplication.java b/android/app/src/main/java/io/metamask/MainApplication.java index 8782cc9fca1..4a79d761e53 100644 --- a/android/app/src/main/java/io/metamask/MainApplication.java +++ b/android/app/src/main/java/io/metamask/MainApplication.java @@ -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 { @@ -53,12 +54,12 @@ 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); + WebView.setWebContentsDebuggingEnabled(true); } /** * Loads Flipper in React Native templates. Call this in the onCreate method with something like diff --git a/android/app/src/main/res/xml/react_native_config.xml b/android/app/src/main/res/xml/react_native_config.xml index 12262fc6cc8..998f2d6083d 100644 --- a/android/app/src/main/res/xml/react_native_config.xml +++ b/android/app/src/main/res/xml/react_native_config.xml @@ -5,5 +5,5 @@ 10.0.2.2 10.0.3.2 - + diff --git a/app/components/Views/BrowserTab/index.js b/app/components/Views/BrowserTab/index.js index 2a36e8a1c5d..fad5f4ddc1a 100644 --- a/app/components/Views/BrowserTab/index.js +++ b/app/components/Views/BrowserTab/index.js @@ -1704,7 +1704,8 @@ export const BrowserTab = props => { javascriptEnabled allowsInlineMediaPlayback useWebkit - testID={'browser-webview'} + testID="browser-webview" + mixedContentMode="compatibility" /> )} From 41b429988c56f2bb0421ce5a22c3ab5a7c858248 Mon Sep 17 00:00:00 2001 From: rickycodes Date: Thu, 1 Oct 2020 21:56:14 -0400 Subject: [PATCH 3/3] Add DEBUG flag for setWebContentsDebuggingEnabled --- android/app/src/main/java/io/metamask/MainApplication.java | 4 +++- .../java/io/metamask/nativeModules/RCTAnalyticsPackage.java | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/io/metamask/MainApplication.java b/android/app/src/main/java/io/metamask/MainApplication.java index 4a79d761e53..d00cd9415a6 100644 --- a/android/app/src/main/java/io/metamask/MainApplication.java +++ b/android/app/src/main/java/io/metamask/MainApplication.java @@ -59,7 +59,9 @@ public void onCreate() { initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); RNBranchModule.getAutoInstance(this); - WebView.setWebContentsDebuggingEnabled(true); + if (BuildConfig.DEBUG) { + WebView.setWebContentsDebuggingEnabled(true); + } } /** * Loads Flipper in React Native templates. Call this in the onCreate method with something like diff --git a/android/app/src/main/java/io/metamask/nativeModules/RCTAnalyticsPackage.java b/android/app/src/main/java/io/metamask/nativeModules/RCTAnalyticsPackage.java index 64cad409dbf..ed04047f319 100644 --- a/android/app/src/main/java/io/metamask/nativeModules/RCTAnalyticsPackage.java +++ b/android/app/src/main/java/io/metamask/nativeModules/RCTAnalyticsPackage.java @@ -17,8 +17,7 @@ public List createViewManagers(ReactApplicationContext reactContext } @Override - public List createNativeModules( - ReactApplicationContext reactContext) { + public List createNativeModules(ReactApplicationContext reactContext) { List modules = new ArrayList<>(); modules.add(new RCTAnalytics(reactContext));