Skip to content

Commit be50e8f

Browse files
committed
Moved from experimental to standard
1 parent 458b89b commit be50e8f

File tree

4 files changed

+47
-39
lines changed

4 files changed

+47
-39
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @name Unsafe resource fetching in Android webview
3+
* @description JavaScript rendered inside WebViews can access any protected
4+
* application file and web resource from any origin
5+
* @kind path-problem
6+
* @problem.severity warning
7+
* @precision medium
8+
* @id java/android/unsafe-android-webview-fetch
9+
* @tags security
10+
* external/cwe/cwe-749
11+
* external/cwe/cwe-079
12+
*/
13+
14+
import java
15+
import semmle.code.java.dataflow.FlowSources
16+
import semmle.code.java.security.UnsafeAndroidAccess
17+
import DataFlow::PathGraph
18+
19+
/**
20+
* Taint configuration tracking flow from untrusted inputs to `loadUrl` or `postUrl` calls.
21+
*/
22+
class FetchUntrustedResourceConfiguration extends TaintTracking::Configuration {
23+
FetchUntrustedResourceConfiguration() { this = "FetchUntrustedResourceConfiguration" }
24+
25+
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
26+
27+
override predicate isSink(DataFlow::Node sink) { sink instanceof FetchUntrustedResourceSink }
28+
}
29+
30+
from DataFlow::PathNode source, DataFlow::PathNode sink, FetchUntrustedResourceConfiguration conf
31+
where conf.hasFlowPath(source, sink)
32+
select sink.getNode().(FetchUntrustedResourceSink).getMethodAccess(), source, sink,
33+
"Unsafe resource fetching in Android webview due to $@.", source.getNode(),
34+
sink.getNode().(FetchUntrustedResourceSink).getSinkType()
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
/**
2-
* @name Unsafe resource fetching in Android webview
3-
* @description JavaScript rendered inside WebViews can access any protected
4-
* application file and web resource from any origin
5-
* @kind path-problem
6-
* @problem.severity warning
7-
* @precision medium
8-
* @id java/android/unsafe-android-webview-fetch
9-
* @tags security
10-
* external/cwe/cwe-749
11-
* external/cwe/cwe-079
12-
*/
13-
141
import java
15-
import semmle.code.java.frameworks.android.Intent
162
import semmle.code.java.frameworks.android.WebView
17-
import semmle.code.java.dataflow.FlowSources
18-
import DataFlow::PathGraph
3+
import semmle.code.java.dataflow.DataFlow
4+
import semmle.code.java.dataflow.ExternalFlow
195

206
/**
217
* Methods allowing any-local-file and cross-origin access in the WebSettings class
228
*/
23-
class CrossOriginAccessMethod extends Method {
9+
private class CrossOriginAccessMethod extends Method {
2410
CrossOriginAccessMethod() {
2511
this.getDeclaringType() instanceof TypeWebSettings and
2612
(
@@ -33,7 +19,7 @@ class CrossOriginAccessMethod extends Method {
3319
/**
3420
* `setJavaScriptEnabled` method for the webview
3521
*/
36-
class AllowJavaScriptMethod extends Method {
22+
private class AllowJavaScriptMethod extends Method {
3723
AllowJavaScriptMethod() {
3824
this.getDeclaringType() instanceof TypeWebSettings and
3925
this.hasName("setJavaScriptEnabled")
@@ -43,7 +29,7 @@ class AllowJavaScriptMethod extends Method {
4329
/**
4430
* Holds if a call to `v.setJavaScriptEnabled(true)` exists
4531
*/
46-
predicate isJSEnabled(Variable v) {
32+
private predicate isJSEnabled(Variable v) {
4733
exists(MethodAccess jsa |
4834
v.getAnAccess() = jsa.getQualifier() and
4935
jsa.getMethod() instanceof AllowJavaScriptMethod and
@@ -54,7 +40,7 @@ predicate isJSEnabled(Variable v) {
5440
/**
5541
* Fetch URL method call on the `android.webkit.WebView` object
5642
*/
57-
class FetchResourceMethodAccess extends MethodAccess {
43+
private class FetchResourceMethodAccess extends MethodAccess {
5844
FetchResourceMethodAccess() {
5945
this.getMethod().getDeclaringType() instanceof TypeWebView and
6046
this.getMethod().hasName(["loadUrl", "postUrl"])
@@ -64,12 +50,14 @@ class FetchResourceMethodAccess extends MethodAccess {
6450
/**
6551
* Holds if `ma` loads URL `sink`
6652
*/
67-
predicate fetchResource(FetchResourceMethodAccess ma, Expr sink) { sink = ma.getArgument(0) }
53+
private predicate fetchResource(FetchResourceMethodAccess ma, Expr sink) {
54+
sink = ma.getArgument(0)
55+
}
6856

6957
/**
7058
* A URL argument to a `loadUrl` or `postUrl` call, considered as a sink.
7159
*/
72-
class UrlResourceSink extends DataFlow::ExprNode {
60+
private class UrlResourceSink extends DataFlow::ExprNode {
7361
UrlResourceSink() { fetchResource(_, this.getExpr()) }
7462

7563
/** Gets the fetch method that fetches this sink URL. */
@@ -103,28 +91,14 @@ class UrlResourceSink extends DataFlow::ExprNode {
10391
}
10492
}
10593

106-
/**
107-
* Taint configuration tracking flow from untrusted inputs to `loadUrl` or `postUrl` calls.
108-
*/
109-
class FetchUntrustedResourceConfiguration extends TaintTracking::Configuration {
110-
FetchUntrustedResourceConfiguration() { this = "FetchUntrustedResourceConfiguration" }
111-
112-
override predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
113-
114-
override predicate isSink(DataFlow::Node sink) {
115-
sink instanceof UrlResourceSink and
94+
class FetchUntrustedResourceSink extends UrlResourceSink {
95+
FetchUntrustedResourceSink() {
11696
exists(VarAccess webviewVa, MethodAccess getSettingsMa, Variable v |
117-
sink.(UrlResourceSink).getMethodAccess().getQualifier() = webviewVa and
97+
this.getMethodAccess().getQualifier() = webviewVa and
11898
getSettingsMa.getMethod() instanceof WebViewGetSettingsMethod and
11999
webviewVa.getVariable().getAnAccess() = getSettingsMa.getQualifier() and
120100
v.getAnAssignedValue() = getSettingsMa and
121101
isJSEnabled(v)
122102
)
123103
}
124104
}
125-
126-
from DataFlow::PathNode source, DataFlow::PathNode sink, FetchUntrustedResourceConfiguration conf
127-
where conf.hasFlowPath(source, sink)
128-
select sink.getNode().(UrlResourceSink).getMethodAccess(), source, sink,
129-
"Unsafe resource fetching in Android webview due to $@.", source.getNode(),
130-
sink.getNode().(UrlResourceSink).getSinkType()

0 commit comments

Comments
 (0)