Skip to content

Commit d68311e

Browse files
committed
Consider implicit this accesses in WebViewRef
1 parent 51dfebf commit d68311e

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

java/ql/lib/semmle/code/java/frameworks/android/WebView.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,28 @@ class ShouldOverrideUrlLoading extends Method {
8181
* Holds if `webview` is a `WebView` and its option `setJavascriptEnabled`
8282
* has been set to `true` via a `WebSettings` object obtained from it.
8383
*/
84-
predicate isJSEnabled(Expr webview) {
84+
predicate isJSEnabled(DataFlow::Node webview) {
8585
webview.getType().(RefType).getASupertype*() instanceof TypeWebView and
8686
exists(MethodAccess allowJs, MethodAccess settings |
8787
allowJs.getMethod() instanceof AllowJavaScriptMethod and
8888
allowJs.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true and
8989
settings.getMethod() instanceof WebViewGetSettingsMethod and
9090
DataFlow::localExprFlow(settings, allowJs.getQualifier()) and
91-
DataFlow::localExprFlow(webview, settings.getQualifier())
91+
DataFlow::localFlow(webview, DataFlow::getInstanceArgument(settings))
9292
)
9393
}
9494

9595
/**
9696
* Holds if `webview` is a `WebView` and its options `setAllowUniversalAccessFromFileURLs` or
9797
* `setAllowFileAccessFromFileURLs` have been set to `true`.
9898
*/
99-
predicate isAllowFileAccessEnabled(Expr webview) {
99+
predicate isAllowFileAccessEnabled(DataFlow::Node webview) {
100100
exists(MethodAccess allowFileAccess, MethodAccess settings |
101101
allowFileAccess.getMethod() instanceof CrossOriginAccessMethod and
102102
allowFileAccess.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true and
103103
settings.getMethod() instanceof WebViewGetSettingsMethod and
104104
DataFlow::localExprFlow(settings, allowFileAccess.getQualifier()) and
105-
DataFlow::localExprFlow(webview, settings.getQualifier())
105+
DataFlow::localFlow(webview, DataFlow::getInstanceArgument(settings))
106106
)
107107
}
108108

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@ private class WebViewRef extends Element {
5757
this.(Variable).getType().(RefType).getASourceSupertype*() instanceof TypeWebView
5858
}
5959

60-
/** Gets an access to this WebView. */
61-
Expr getAnAccess() {
62-
exists(ThisAccess t | t.getType() = this and result = t |
63-
t.isOwnInstanceAccess() or
64-
t.isEnclosingInstanceAccess(this)
60+
/** Gets an access to this WebView as a data flow node. */
61+
DataFlow::Node getAnAccess() {
62+
exists(DataFlow::InstanceAccessNode t | t.getType() = this and result = t |
63+
t.isOwnInstanceAccess() or t.getInstanceAccess().isEnclosingInstanceAccess(this)
6564
)
6665
or
67-
result = this.(Variable).getAnAccess()
66+
result = DataFlow::exprNode(this.(Variable).getAnAccess())
6867
}
6968
}
7069

@@ -80,20 +79,25 @@ private Expr getUnderlyingExpr(Expr e) {
8079
* Holds if a `WebViewLoadUrlMethod` is called on `webview`
8180
* with `urlArg` as its first argument.
8281
*/
83-
private predicate webViewLoadUrl(Argument urlArg, Expr webview) {
82+
private predicate webViewLoadUrl(Argument urlArg, DataFlow::Node webview) {
8483
exists(MethodAccess loadUrl |
8584
loadUrl.getArgument(0) = urlArg and
8685
loadUrl.getMethod() instanceof WebViewLoadUrlMethod
8786
|
88-
getUnderlyingExpr(loadUrl.getQualifier()) = webview
87+
webview = DataFlow::exprNode(getUnderlyingExpr(loadUrl.getQualifier()))
88+
or
89+
webview = DataFlow::getInstanceArgument(loadUrl)
8990
or
9091
// `webview` is received as a parameter of an event method in a custom `WebViewClient`,
9192
// so we need to find WebViews that use that specific `WebViewClient`.
9293
exists(WebViewClientEventMethod eventMethod, MethodAccess setWebClient |
9394
setWebClient.getMethod() instanceof WebViewSetWebViewClientMethod and
9495
setWebClient.getArgument(0).getType() = eventMethod.getDeclaringType() and
95-
getUnderlyingExpr(setWebClient.getQualifier()) = webview and
9696
getUnderlyingExpr(loadUrl.getQualifier()) = eventMethod.getWebViewParameter().getAnAccess()
97+
|
98+
webview = DataFlow::exprNode(getUnderlyingExpr(setWebClient.getQualifier()))
99+
or
100+
webview = DataFlow::getInstanceArgument(setWebClient)
97101
)
98102
)
99103
}

0 commit comments

Comments
 (0)