Skip to content

Commit 657f615

Browse files
committed
Fine tune the query and update qldoc
1 parent 88d9694 commit 657f615

File tree

4 files changed

+84
-73
lines changed

4 files changed

+84
-73
lines changed

java/ql/src/experimental/Security/CWE/CWE-200/AndroidWebResourceResponse.qll

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,19 @@ class WebResourceResponse extends RefType {
2121
class ShouldInterceptRequestMethod extends Method {
2222
ShouldInterceptRequestMethod() {
2323
this.hasName("shouldInterceptRequest") and
24-
this.getDeclaringType().getASupertype*() instanceof TypeWebViewClient and
25-
this.getReturnType() instanceof WebResourceResponse
24+
this.getDeclaringType().getASupertype*() instanceof TypeWebViewClient
2625
}
2726
}
2827

2928
/** A method call to `setWebViewClient` of `WebView`. */
3029
class SetWebViewClientMethodAccess extends MethodAccess {
3130
SetWebViewClientMethodAccess() {
3231
this.getMethod().hasName("setWebViewClient") and
33-
this.getMethod().getDeclaringType().getASupertype*() instanceof TypeWebView and
34-
this.getMethod().getParameterType(0) instanceof TypeWebViewClient
32+
this.getMethod().getDeclaringType().getASupertype*() instanceof TypeWebView
3533
}
3634
}
3735

38-
/** A sink representing a constructor call of `WebResourceResponse` in Android `WebViewClient`. */
36+
/** A sink representing the data argument of a call to the constructor of `WebResourceResponse`. */
3937
class WebResourceResponseSink extends DataFlow::Node {
4038
WebResourceResponseSink() {
4139
exists(ConstructorCall cc |
@@ -50,7 +48,8 @@ class WebResourceResponseSink extends DataFlow::Node {
5048
}
5149

5250
/**
53-
* Value step from a fetching url call of `WebView` to `WebViewClient`.
51+
* A value step from the URL argument of `WebView::loadUrl` to the URL parameter of
52+
* `WebViewClient::shouldInterceptRequest`.
5453
*/
5554
private class FetchUrlStep extends AdditionalValueStep {
5655
override predicate step(DataFlow::Node pred, DataFlow::Node succ) {
@@ -63,20 +62,20 @@ private class FetchUrlStep extends AdditionalValueStep {
6362
lma.getMethod() = lm and
6463
lma.getQualifier().getType() = sma.getQualifier().getType() and
6564
pred.asExpr() = lma.getArgument(0) and
66-
succ.asExpr() = im.getParameter(1).getAnAccess()
65+
succ.asParameter() = im.getParameter(1)
6766
)
6867
)
6968
}
7069
}
7170

7271
/** Value/taint steps relating to url loading and file reading in an Android application. */
73-
private class LoadUrlSource extends SummaryModelCsv {
72+
private class LoadUrlSummaries extends SummaryModelCsv {
7473
override predicate row(string row) {
7574
row =
7675
[
7776
"java.io;FileInputStream;true;FileInputStream;;;Argument[0];Argument[-1];taint",
78-
"android.net;Uri;false;getPath;;;Argument[0];ReturnValue;value",
79-
"android.webkit;WebResourceRequest;false;getUrl;;;Argument[-1];ReturnValue;value"
77+
"android.net;Uri;false;getPath;;;Argument[0];ReturnValue;taint",
78+
"android.webkit;WebResourceRequest;false;getUrl;;;Argument[-1];ReturnValue;taint"
8079
]
8180
}
8281
}

java/ql/src/experimental/Security/CWE/CWE-200/InsecureWebResourceResponse.qhelp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33
"qhelp.dtd">
44
<qhelp>
55
<overview>
6-
<p>Android provides a <code>WebResourceResponse</code> API, which is a <code>WebView</code> class that
7-
allows an Android application to behave as a web server by handling requests of popular protocols such
8-
as <code>http(s)</code>, <code>file</code>, as well as <code>javascript</code>; and returning a response
9-
(including status code, content type, content encoding, headers and the response body). Improper
10-
implementation with insufficient input validation can lead to leaking of sensitive configuration file
11-
or user data because requests could refer to paths intended to be application-private.
6+
<p>Android provides a <code>WebResourceResponse</code> class, which allows an Android application to behave
7+
as a web server by handling requests of popular protocols such as <code>http(s)</code>, <code>file</code>,
8+
as well as <code>javascript</code>; and returning a response (including status code, content type, content
9+
encoding, headers and the response body). Improper implementation with insufficient input validation can lead
10+
to leakage of sensitive configuration files or user data because requests could refer to paths intended to be
11+
application-private.
1212
</p>
1313
</overview>
1414

1515
<recommendation>
1616
<p>
17-
Unsanitized user provided url must not be used to serve a response directly. When handling a request,
18-
always validate that the file path is not the receiver's protected directory. Alternatively the Android
19-
API <code>WebViewAssetLoader</code> can be used, which safely processes data from resources, assets or
20-
a predefined directory.
17+
Unsanitized user-provided URLs must not be used to serve a response directly. When handling a request,
18+
always validate that the requested file path is not in the receiver's protected directory. Alternatively
19+
the Android class <code>WebViewAssetLoader</code> can be used, which safely processes data from resources,
20+
assets or a predefined directory.
2121
</p>
2222
</recommendation>
2323

2424
<example>
2525
<p>
26-
The following examples show a bad situation and two good situations respectively. In the bad situation, a
27-
response is served without path validation. In the good situation, a response is either served with path
26+
The following examples show a bad scenario and two good scenarios respectively. In the bad scenario, a
27+
response is served without path validation. In the good scenario, a response is either served with path
2828
validation or through the safe <code>WebViewAssetLoader</code> implementation.
2929
</p>
3030
<sample src="InsecureWebResourceResponse.java" />
3131
</example>
3232

3333
<references>
3434
<li>
35-
Google:
35+
Oversecured:
3636
<a href="https://blog.oversecured.com/Android-Exploring-vulnerabilities-in-WebResourceResponse/">Android: Exploring vulnerabilities in WebResourceResponse</a>.
3737
</li>
3838
<li>

java/ql/src/experimental/Security/CWE/CWE-200/InsecureWebResourceResponse.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Insecure Android WebView Resource Response
3-
* @description Insecure implementation of Android WebResourceResponse intercepts malicious app requests
4-
* and return arbitrary sensitive content.
3+
* @description An insecure implementation of Android `WebResourceResponse` may lead to leakage of arbitrary
4+
* sensitive content.
55
* @kind path-problem
66
* @id java/insecure-webview-resource-response
77
* @problem.severity error
@@ -29,5 +29,5 @@ class InsecureWebResourceResponseConfig extends TaintTracking::Configuration {
2929

3030
from DataFlow::PathNode source, DataFlow::PathNode sink, InsecureWebResourceResponseConfig conf
3131
where conf.hasFlowPath(source, sink)
32-
select sink.getNode(), source, sink, "Leaking arbitrary content in Android from $@.", source.getNode(),
33-
"this user input"
32+
select sink.getNode(), source, sink, "Leaking arbitrary content in Android from $@.",
33+
source.getNode(), "this user input"

0 commit comments

Comments
 (0)