Skip to content

Commit 768102e

Browse files
committed
Refactor java/android/webview-debugging-enabled
1 parent 559f6a5 commit 768102e

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

java/ql/lib/semmle/code/java/security/WebviewDubuggingEnabledQuery.qll renamed to java/ql/lib/semmle/code/java/security/WebviewDebuggingEnabledQuery.qll

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ private predicate isDebugCheck(Expr ex) {
1818
)
1919
}
2020

21-
/** A configuration to find instances of `setWebContentDebuggingEnabled` called with `true` values. */
22-
class WebviewDebugEnabledConfig extends DataFlow::Configuration {
21+
/**
22+
* DEPRECATED: Use `WebviewDebugEnabledFlow` instead.
23+
*
24+
* A configuration to find instances of `setWebContentDebuggingEnabled` called with `true` values.
25+
*/
26+
deprecated class WebviewDebugEnabledConfig extends DataFlow::Configuration {
2327
WebviewDebugEnabledConfig() { this = "WebviewDebugEnabledConfig" }
2428

2529
override predicate isSource(DataFlow::Node node) {
@@ -39,3 +43,25 @@ class WebviewDebugEnabledConfig extends DataFlow::Configuration {
3943
node.getEnclosingCallable().getDeclaringType() instanceof NonSecurityTestClass
4044
}
4145
}
46+
47+
/** A configuration to find instances of `setWebContentDebuggingEnabled` called with `true` values. */
48+
private module WebviewDebugEnabledConfig implements DataFlow::ConfigSig {
49+
predicate isSource(DataFlow::Node node) {
50+
node.asExpr().(BooleanLiteral).getBooleanValue() = true
51+
}
52+
53+
predicate isSink(DataFlow::Node node) {
54+
exists(MethodAccess ma |
55+
ma.getMethod().hasQualifiedName("android.webkit", "WebView", "setWebContentsDebuggingEnabled") and
56+
node.asExpr() = ma.getArgument(0)
57+
)
58+
}
59+
60+
predicate isBarrier(DataFlow::Node node) {
61+
exists(Guard debug | isDebugCheck(debug) and debug.controls(node.asExpr().getBasicBlock(), _))
62+
or
63+
node.getEnclosingCallable().getDeclaringType() instanceof NonSecurityTestClass
64+
}
65+
}
66+
67+
module WebviewDebugEnabledFlow = DataFlow::Make<WebviewDebugEnabledConfig>;

java/ql/src/Security/CWE/CWE-489/WebviewDebuggingEnabled.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*/
1212

1313
import java
14-
import semmle.code.java.security.WebviewDubuggingEnabledQuery
15-
import DataFlow::PathGraph
14+
import semmle.code.java.security.WebviewDebuggingEnabledQuery
15+
import WebviewDebugEnabledFlow::PathGraph
1616

17-
from WebviewDebugEnabledConfig conf, DataFlow::PathNode source, DataFlow::PathNode sink
18-
where conf.hasFlowPath(source, sink)
17+
from WebviewDebugEnabledFlow::PathNode source, WebviewDebugEnabledFlow::PathNode sink
18+
where WebviewDebugEnabledFlow::hasFlowPath(source, sink)
1919
select sink, source, sink, "Webview debugging is enabled."
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import java
2-
import TestUtilities.InlineFlowTest
3-
import semmle.code.java.security.WebviewDubuggingEnabledQuery
2+
import TestUtilities.InlineExpectationsTest
3+
import semmle.code.java.security.WebviewDebuggingEnabledQuery
44

5-
class EnableLegacy extends EnableLegacyConfiguration {
6-
EnableLegacy() { exists(this) }
7-
}
5+
class HasFlowTest extends InlineExpectationsTest {
6+
HasFlowTest() { this = "HasFlowTest" }
87

9-
class HasFlowTest extends InlineFlowTest {
10-
override DataFlow::Configuration getTaintFlowConfig() { none() }
8+
override string getARelevantTag() { result = "hasValueFlow" }
119

12-
override DataFlow::Configuration getValueFlowConfig() {
13-
result = any(WebviewDebugEnabledConfig c)
10+
override predicate hasActualResult(Location location, string element, string tag, string value) {
11+
tag = "hasValueFlow" and
12+
exists(DataFlow::Node sink | WebviewDebugEnabledFlow::hasFlowTo(sink) |
13+
location = sink.getLocation() and
14+
element = "sink" and
15+
value = ""
16+
)
1417
}
1518
}

0 commit comments

Comments
 (0)