Skip to content

Commit e1d0777

Browse files
authored
fix(android): Add mitigation strategy for CVE-2020-6506 (apache#792)
1 parent 2e6d637 commit e1d0777

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/android/InAppBrowser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,9 @@ public void postMessage(String data) {
10421042
inAppWebView.setId(Integer.valueOf(6));
10431043
inAppWebView.getSettings().setLoadWithOverviewMode(true);
10441044
inAppWebView.getSettings().setUseWideViewPort(useWideViewPort);
1045+
// Multiple Windows set to true to mitigate Chromium security bug.
1046+
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=1083819
1047+
inAppWebView.getSettings().setSupportMultipleWindows(true);
10451048
inAppWebView.requestFocus();
10461049
inAppWebView.requestFocusFromTouch();
10471050

src/android/InAppChromeClient.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ Licensed to the Apache Software Foundation (ASF) under one
2424
import org.json.JSONArray;
2525
import org.json.JSONException;
2626

27+
import android.annotation.TargetApi;
28+
import android.os.Build;
29+
import android.os.Message;
2730
import android.webkit.JsPromptResult;
2831
import android.webkit.WebChromeClient;
32+
import android.webkit.WebResourceRequest;
2933
import android.webkit.WebStorage;
3034
import android.webkit.WebView;
3135
import android.webkit.WebViewClient;
@@ -135,4 +139,45 @@ public boolean onJsPrompt(WebView view, String url, String message, String defau
135139
return false;
136140
}
137141

142+
/**
143+
* The InAppWebBrowser WebView is configured to MultipleWindow mode to mitigate a security
144+
* bug found in Chromium prior to version 83.0.4103.106.
145+
* See https://bugs.chromium.org/p/chromium/issues/detail?id=1083819
146+
*
147+
* Valid Urls set to open in new window will be routed back to load in the original WebView.
148+
*
149+
* @param view
150+
* @param isDialog
151+
* @param isUserGesture
152+
* @param resultMsg
153+
* @return
154+
*/
155+
@Override
156+
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
157+
WebView inAppWebView = view;
158+
final WebViewClient webViewClient =
159+
new WebViewClient() {
160+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
161+
@Override
162+
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
163+
inAppWebView.loadUrl(request.getUrl().toString());
164+
return true;
165+
}
166+
167+
@Override
168+
public boolean shouldOverrideUrlLoading(WebView view, String url) {
169+
inAppWebView.loadUrl(url);
170+
return true;
171+
}
172+
};
173+
174+
final WebView newWebView = new WebView(view.getContext());
175+
newWebView.setWebViewClient(webViewClient);
176+
177+
final WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
178+
transport.setWebView(newWebView);
179+
resultMsg.sendToTarget();
180+
181+
return true;
182+
}
138183
}

0 commit comments

Comments
 (0)