Skip to content

Commit e4e13d3

Browse files
committed
Java: query for Android WebView setAllowContentAccess
1 parent e259ef5 commit e4e13d3

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>Android can provide access to content providers within a WebView using
7+
the <code>setAllowContentAccess</code> setting.</p>
8+
9+
<p>Allowing access to content providers via <code>content://</code> URLs
10+
may allow JavaScript to access protected content.</p>
11+
</overview>
12+
13+
<recommendation>
14+
<p>
15+
If your app does not require access to the <code>content://</code> URL
16+
functionality, you should explicitly disable the setting by
17+
calling <code>setAllowContentAccess(false)</code> on the settings of the
18+
WebView.
19+
</p>
20+
</recommendation>
21+
22+
<example>
23+
<p>In the following (bad) example, access to <code>content://</code> URLs is explicitly allowed.</p>
24+
25+
<sample src="ContentAccessEnabled.java"/>
26+
27+
</example>
28+
29+
<references>
30+
<li>
31+
Android Documentation: <a href="https://developer.android.com/reference/android/webkit/WebSettings#setAllowContentAccess(boolean)">setAllowContentAccess</a>.
32+
</li>
33+
</references>
34+
35+
</qhelp>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @name Android WebSettings content access
3+
* @description Access to content providers in a WebView can enable JavaScript to access protected information.
4+
* @kind problem
5+
* @id java/android-websettings-content-access
6+
* @problem.severity warning
7+
* @security-severity 6.5
8+
* @precision high
9+
* @tags security
10+
* external/cwe/cwe-200
11+
*/
12+
13+
import java
14+
import semmle.code.java.frameworks.android.WebView
15+
16+
from MethodAccess ma
17+
where
18+
ma.getMethod() instanceof AllowContentAccessMethod and
19+
ma.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true
20+
select ma,
21+
"Sensitive information may be exposed via a malicious link due to access of content:// links being permitted."
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
WebSettings settings = webview.getSettings();
2+
3+
settings.setAllowContentAccess(true);

0 commit comments

Comments
 (0)