Skip to content

Commit f934554

Browse files
Add docs + add an additional case
1 parent b3d9d08 commit f934554

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

java/ql/lib/semmle/code/java/security/WebviewDubuggingEnabledQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import semmle.code.java.security.SecurityTests
88
/** Holds if `ex` looks like a check that this is a debug build. */
99
private predicate isDebugCheck(Expr ex) {
1010
exists(Expr subex, string debug |
11-
debug.toLowerCase().matches("%debug%") and
11+
(
12+
debug.toLowerCase().matches("%debug%")
13+
or
14+
debug.toLowerCase().matches("%test%")
15+
) and
1216
subex.getParent*() = ex
1317
|
1418
subex.(VarAccess).getVariable().getName() = debug
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// BAD - debugging is always enabled
2+
WebView.setWebContentsDebuggingEnabled(true);
3+
4+
// GOOD - debugging is only enabled when this is a debug build, as indicated by the debuggable flag being set.
5+
if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
6+
WebView.setWebContentsDebuggingEnabled(true);
7+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>The <code>WebView.setWebContentsDebuggingEnabled</code> method enables or disables the contents of any <code>WebView</code> in the application to be debugged.</p>
8+
9+
<p>Enabling debugging featues could allow for additional entry points or leaking sensitive information.
10+
As such, debugging should only be anabled during development, and disabled during production builds.
11+
</overview>
12+
<recommendation>
13+
Ensure that debugging features are not enabled during production builds.
14+
If <code>WebView.setWebContentsDebuggingEnabled(true)</code> is used, ensure that it is guarded by a flag indicating that this is a debug build.
15+
16+
</recommendation>
17+
<example>
18+
19+
<p>In the code below, the BAD case shows debugging always being enabled,
20+
whereas the GOOD case only enables debugging if the <code>android:debuggable</code> attribute is set to <code>true</code>.</p>
21+
22+
<sample src="WebviewDebuggingEnabled.java" />
23+
24+
</example>
25+
<references>
26+
27+
<li>
28+
Android Developers:
29+
<a href="https://developer.android.com/reference/android/webkit/WebView.html#setWebContentsDebuggingEnabled(boolean)">setWebContentsDebuggingEnabled</a>.
30+
</li>
31+
32+
<li>
33+
Android Developers:
34+
<a href="https://developer.chrome.com/docs/devtools/remote-debugging/webviews/">Remote debugging WebViews</a>.
35+
</li>
36+
37+
</references>
38+
</qhelp>

0 commit comments

Comments
 (0)