Skip to content

Commit 9ef319f

Browse files
committed
Java: setAllowContentAccess query tests
1 parent 5265cb4 commit 9ef319f

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed
Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,59 @@
11
package com.example.test;
22

3+
import android.app.Activity;
4+
35
import android.webkit.WebView;
46
import android.webkit.WebSettings;
57

6-
public class WebViewContentAccess {
7-
void configureWebViewUnsafe(WebView view) {
8-
WebSettings settings = view.getSettings();
8+
/** Helper class to mock a method which returns a `WebView` */
9+
interface WebViewGetter {
10+
WebView getAWebView();
11+
}
912

10-
settings.setAllowContentAccess(true);
13+
public class WebViewContentAccess extends Activity {
14+
void enableContentAccess(WebView webview) {
15+
webview.getSettings().setAllowContentAccess(true);
16+
}
17+
18+
void disableContentAccess(WebView webview) {
19+
webview.getSettings().setAllowContentAccess(false);
1120
}
1221

13-
void configureWebViewSafe(WebView view) {
22+
void configureWebViewSafe(WebView view, WebViewGetter getter) {
1423
WebSettings settings = view.getSettings();
1524

1625
settings.setAllowContentAccess(false);
26+
27+
WebView view2 = (WebView) findViewById(0);
28+
settings = view2.getSettings();
29+
30+
settings.setAllowContentAccess(false);
31+
32+
disableContentAccess(getter.getAWebView());
33+
}
34+
35+
void configureWebViewUnsafe(WebView view1, WebViewGetter getter) {
36+
WebSettings settings;
37+
38+
view1.getSettings().setAllowContentAccess(true);
39+
40+
// Cast expression
41+
WebView view2 = (WebView) findViewById(0);
42+
settings = view2.getSettings();
43+
settings.setAllowContentAccess(true);
44+
45+
// Constructor
46+
WebView view3 = new WebView(this);
47+
settings = view3.getSettings();
48+
settings.setAllowContentAccess(true);
49+
50+
// Method access
51+
WebView view4 = getter.getAWebView();
52+
settings = view4.getSettings();
53+
settings.setAllowContentAccess(true);
54+
55+
enableContentAccess(getter.getAWebView());
56+
57+
WebView view5 = getter.getAWebView();
1758
}
1859
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| WebViewContentAccess.java:41:25:41:49 | (...)... | Sensitive information may be exposed via a malicious link due to access of content:// links being permitted. |
2+
| WebViewContentAccess.java:46:25:46:41 | new WebView(...) | Sensitive information may be exposed via a malicious link due to access of content:// links being permitted. |
3+
| WebViewContentAccess.java:51:25:51:44 | getAWebView(...) | Sensitive information may be exposed via a malicious link due to access of content:// links being permitted. |
4+
| WebViewContentAccess.java:55:29:55:48 | getAWebView(...) | Sensitive information may be exposed via a malicious link due to access of content:// links being permitted. |
5+
| WebViewContentAccess.java:57:25:57:44 | getAWebView(...) | Sensitive information may be exposed via a malicious link due to access of content:// links being permitted. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE/CWE-200/AndroidWebViewSettingsPermitsContentAccess.ql

0 commit comments

Comments
 (0)