Skip to content

Commit da25c58

Browse files
committed
Dataflow query for detecting paths that disable content access
Since the default value is `true`, we need to determine whether or not the `setAllowContentAccess` method is ever called using dataflow.
1 parent 8a76301 commit da25c58

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @id java/android-websettings-permit-contentacces
3+
*/
4+
5+
import java
6+
import semmle.code.java.dataflow.DataFlow
7+
import semmle.code.java.frameworks.android.WebView
8+
9+
private class TypeWebViewOrSubclass extends RefType {
10+
TypeWebViewOrSubclass() { this.getASupertype*() instanceof TypeWebView }
11+
}
12+
13+
// source: WebView
14+
// sink: settings.setAllowContentAccess(false)
15+
class WebViewDisallowContentAccessConfiguration extends DataFlow::Configuration {
16+
WebViewDisallowContentAccessConfiguration() { this = "WebViewDisallowContentAccessConfiguration" }
17+
18+
override predicate isSource(DataFlow::Node source) {
19+
source.asExpr().getType() instanceof TypeWebViewOrSubclass and
20+
(
21+
source.asExpr() instanceof ClassInstanceExpr or
22+
source.asExpr() instanceof MethodAccess or
23+
source.asExpr().(CastExpr).getAChildExpr() instanceof MethodAccess
24+
)
25+
}
26+
27+
override predicate isSink(DataFlow::Node sink) {
28+
exists(MethodAccess ma |
29+
ma = sink.asExpr() and
30+
ma.getMethod().hasName("setAllowContentAccess") and
31+
ma.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = false
32+
)
33+
}
34+
}
35+
36+
from DataFlow::Node e, WebViewDisallowContentAccessConfiguration cfg
37+
where cfg.isSource(e) and not cfg.hasFlow(e, _)
38+
select e

0 commit comments

Comments
 (0)