Skip to content

Commit 8601137

Browse files
committed
Fix bad join order by moving WebViewRef::getAnAccess from callsites into predicates
1 parent 3b1210e commit 8601137

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ abstract class UrlResourceSink extends DataFlow::Node {
2626
private class CrossOriginUrlResourceSink extends JavaScriptEnabledUrlResourceSink {
2727
CrossOriginUrlResourceSink() {
2828
exists(WebViewRef webview |
29-
webViewLoadUrl(this.asExpr(), webview.getAnAccess()) and
30-
isAllowFileAccessEnabled(webview.getAnAccess())
29+
webViewLoadUrl(this.asExpr(), webview) and
30+
isAllowFileAccessEnabled(webview)
3131
)
3232
}
3333

@@ -42,8 +42,8 @@ private class CrossOriginUrlResourceSink extends JavaScriptEnabledUrlResourceSin
4242
private class JavaScriptEnabledUrlResourceSink extends UrlResourceSink {
4343
JavaScriptEnabledUrlResourceSink() {
4444
exists(WebViewRef webview |
45-
webViewLoadUrl(this.asExpr(), webview.getAnAccess()) and
46-
isJSEnabled(webview.getAnAccess())
45+
webViewLoadUrl(this.asExpr(), webview) and
46+
isJSEnabled(webview)
4747
)
4848
}
4949

@@ -67,15 +67,15 @@ private class WebViewRef extends Element {
6767
}
6868

6969
/**
70-
* Holds if a `WebViewLoadUrlMethod` is called on `webview`
70+
* Holds if a `WebViewLoadUrlMethod` is called on an access of `webview`
7171
* with `urlArg` as its first argument.
7272
*/
73-
private predicate webViewLoadUrl(Argument urlArg, DataFlow::Node webview) {
73+
private predicate webViewLoadUrl(Argument urlArg, WebViewRef webview) {
7474
exists(MethodAccess loadUrl |
7575
loadUrl.getArgument(0) = urlArg and
7676
loadUrl.getMethod() instanceof WebViewLoadUrlMethod
7777
|
78-
webview = DataFlow::getInstanceArgument(loadUrl)
78+
webview.getAnAccess() = DataFlow::getInstanceArgument(loadUrl)
7979
or
8080
// `webview` is received as a parameter of an event method in a custom `WebViewClient`,
8181
// so we need to find `WebViews` that use that specific `WebViewClient`.
@@ -84,37 +84,37 @@ private predicate webViewLoadUrl(Argument urlArg, DataFlow::Node webview) {
8484
setWebClient.getArgument(0).getType() = eventMethod.getDeclaringType() and
8585
loadUrl.getQualifier() = eventMethod.getWebViewParameter().getAnAccess()
8686
|
87-
webview = DataFlow::getInstanceArgument(setWebClient)
87+
webview.getAnAccess() = DataFlow::getInstanceArgument(setWebClient)
8888
)
8989
)
9090
}
9191

9292
/**
93-
* Holds if `webview` is a `WebView` and its option `setJavascriptEnabled`
93+
* Holds if `webview`'s option `setJavascriptEnabled`
9494
* has been set to `true` via a `WebSettings` object obtained from it.
9595
*/
96-
private predicate isJSEnabled(DataFlow::Node webview) {
97-
webview.getType().(RefType).getASupertype*() instanceof TypeWebView and
96+
private predicate isJSEnabled(WebViewRef webview) {
9897
exists(MethodAccess allowJs, MethodAccess settings |
9998
allowJs.getMethod() instanceof AllowJavaScriptMethod and
10099
allowJs.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true and
101100
settings.getMethod() instanceof WebViewGetSettingsMethod and
102101
DataFlow::localExprFlow(settings, allowJs.getQualifier()) and
103-
DataFlow::localFlow(webview, DataFlow::getInstanceArgument(settings))
102+
DataFlow::localFlow(webview.getAnAccess(), DataFlow::getInstanceArgument(settings))
104103
)
105104
}
106105

107106
/**
108-
* Holds if `webview` is a `WebView` and its options `setAllowUniversalAccessFromFileURLs` or
109-
* `setAllowFileAccessFromFileURLs` have been set to `true`.
107+
* Holds if `webview`'s options `setAllowUniversalAccessFromFileURLs` or
108+
* `setAllowFileAccessFromFileURLs` have been set to `true` via a `WebSettings` object
109+
* obtained from it.
110110
*/
111-
private predicate isAllowFileAccessEnabled(DataFlow::Node webview) {
111+
private predicate isAllowFileAccessEnabled(WebViewRef webview) {
112112
exists(MethodAccess allowFileAccess, MethodAccess settings |
113113
allowFileAccess.getMethod() instanceof CrossOriginAccessMethod and
114114
allowFileAccess.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true and
115115
settings.getMethod() instanceof WebViewGetSettingsMethod and
116116
DataFlow::localExprFlow(settings, allowFileAccess.getQualifier()) and
117-
DataFlow::localFlow(webview, DataFlow::getInstanceArgument(settings))
117+
DataFlow::localFlow(webview.getAnAccess(), DataFlow::getInstanceArgument(settings))
118118
)
119119
}
120120

0 commit comments

Comments
 (0)