|
1 | 1 | import java
|
| 2 | +private import semmle.code.java.dataflow.DataFlow |
| 3 | +private import semmle.code.java.dataflow.ExternalFlow |
2 | 4 |
|
| 5 | +/** The class `android.webkit.WebView`. */ |
3 | 6 | class TypeWebView extends Class {
|
4 | 7 | TypeWebView() { this.hasQualifiedName("android.webkit", "WebView") }
|
5 | 8 | }
|
6 | 9 |
|
| 10 | +/** The class `android.webkit.WebViewClient`. */ |
7 | 11 | class TypeWebViewClient extends Class {
|
8 | 12 | TypeWebViewClient() { this.hasQualifiedName("android.webkit", "WebViewClient") }
|
9 | 13 | }
|
10 | 14 |
|
| 15 | +/** The class `android.webkit.WebSettings`. */ |
11 | 16 | class TypeWebSettings extends Class {
|
12 | 17 | TypeWebSettings() { this.hasQualifiedName("android.webkit", "WebSettings") }
|
13 | 18 | }
|
14 | 19 |
|
| 20 | +/** The method `getSettings` of the class `android.webkit.WebView`. */ |
15 | 21 | class WebViewGetSettingsMethod extends Method {
|
16 | 22 | WebViewGetSettingsMethod() {
|
17 | 23 | this.hasName("getSettings") and
|
18 | 24 | this.getDeclaringType() instanceof TypeWebView
|
19 | 25 | }
|
20 | 26 | }
|
21 | 27 |
|
| 28 | +/** The method `loadUrl` or `postUrl` of the class `android.webkit.WebView`. */ |
22 | 29 | class WebViewLoadUrlMethod extends Method {
|
23 | 30 | WebViewLoadUrlMethod() {
|
24 | 31 | this.getDeclaringType() instanceof TypeWebView and
|
25 | 32 | (this.hasName("loadUrl") or this.hasName("postUrl"))
|
26 | 33 | }
|
27 | 34 | }
|
28 | 35 |
|
| 36 | +/** The method `getUrl` or `getOriginalUrl` of the class `android.webkit.WebView`. */ |
29 | 37 | class WebViewGetUrlMethod extends Method {
|
30 | 38 | WebViewGetUrlMethod() {
|
31 | 39 | this.getDeclaringType() instanceof TypeWebView and
|
32 | 40 | (this.getName() = "getUrl" or this.getName() = "getOriginalUrl")
|
33 | 41 | }
|
34 | 42 | }
|
| 43 | + |
| 44 | +/** |
| 45 | + * A method allowing any-local-file and cross-origin access in the class `android.webkit.WebSettings`. |
| 46 | + */ |
| 47 | +class CrossOriginAccessMethod extends Method { |
| 48 | + CrossOriginAccessMethod() { |
| 49 | + this.getDeclaringType() instanceof TypeWebSettings and |
| 50 | + this.hasName(["setAllowUniversalAccessFromFileURLs", "setAllowFileAccessFromFileURLs"]) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +/** |
| 55 | + * The method `setJavaScriptEnabled` of the class `android.webkit.WebSettings`. |
| 56 | + */ |
| 57 | +class AllowJavaScriptMethod extends Method { |
| 58 | + AllowJavaScriptMethod() { |
| 59 | + this.getDeclaringType() instanceof TypeWebSettings and |
| 60 | + this.hasName("setJavaScriptEnabled") |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +/** The method `setWebViewClient` of the class `android.webkit.WebView`. */ |
| 65 | +class WebViewSetWebViewClientMethod extends Method { |
| 66 | + WebViewSetWebViewClientMethod() { |
| 67 | + this.getDeclaringType() instanceof TypeWebView and |
| 68 | + this.hasName("setWebViewClient") |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/** The method `shouldOverrideUrlLoading` of the class `android.webkit.WebViewClient`. */ |
| 73 | +class ShouldOverrideUrlLoading extends Method { |
| 74 | + ShouldOverrideUrlLoading() { |
| 75 | + this.getDeclaringType().getASupertype*() instanceof TypeWebViewClient and |
| 76 | + this.hasName("shouldOverrideUrlLoading") |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * Holds if `webview` is a `WebView` and its option `setJavascriptEnabled` |
| 82 | + * has been set to `true` via a `WebSettings` object obtained from it. |
| 83 | + */ |
| 84 | +predicate isJSEnabled(Expr webview) { |
| 85 | + webview.getType().(RefType).getASupertype*() instanceof TypeWebView and |
| 86 | + exists(MethodAccess allowJs | |
| 87 | + allowJs.getMethod() instanceof AllowJavaScriptMethod and |
| 88 | + allowJs.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true and |
| 89 | + exists(MethodAccess settings | |
| 90 | + settings.getMethod() instanceof WebViewGetSettingsMethod and |
| 91 | + DataFlow::localExprFlow(settings, allowJs.getQualifier()) and |
| 92 | + DataFlow::localExprFlow(webview, settings.getQualifier()) |
| 93 | + ) |
| 94 | + ) |
| 95 | +} |
| 96 | + |
| 97 | +/** |
| 98 | + * Holds if `webview` is a `WebView` and its options `setAllowUniversalAccessFromFileURLs` or |
| 99 | + * `setAllowFileAccessFromFileURLs` have been set to `true`. |
| 100 | + */ |
| 101 | +predicate isAllowFileAccessEnabled(Expr webview) { |
| 102 | + exists(MethodAccess allowFileAccess | |
| 103 | + allowFileAccess.getMethod() instanceof CrossOriginAccessMethod and |
| 104 | + allowFileAccess.getArgument(0).(CompileTimeConstantExpr).getBooleanValue() = true and |
| 105 | + exists(MethodAccess settings | |
| 106 | + settings.getMethod() instanceof WebViewGetSettingsMethod and |
| 107 | + DataFlow::localExprFlow(settings, allowFileAccess.getQualifier()) and |
| 108 | + DataFlow::localExprFlow(webview, settings.getQualifier()) |
| 109 | + ) |
| 110 | + ) |
| 111 | +} |
| 112 | + |
| 113 | +private class WebkitSourceModels extends SourceModelCsv { |
| 114 | + override predicate row(string row) { |
| 115 | + row = |
| 116 | + [ |
| 117 | + "android.webkit;WebResourceRequest;true;doUpdateVisitedHistory;;;Parameter[1];remote", |
| 118 | + "android.webkit;WebResourceRequest;true;onLoadResource;;;Parameter[1];remote", |
| 119 | + "android.webkit;WebResourceRequest;true;onPageCommitVisible;;;Parameter[1];remote", |
| 120 | + "android.webkit;WebResourceRequest;true;onPageFinished;;;Parameter[1];remote", |
| 121 | + "android.webkit;WebResourceRequest;true;onPageStarted;;;Parameter[1];remote", |
| 122 | + "android.webkit;WebResourceRequest;true;onReceivedError;(WebView,int,String,String);;Parameter[3];remote", |
| 123 | + "android.webkit;WebResourceRequest;true;onReceivedError;(WebView,WebResourceRequest,WebResourceError);;Parameter[1];remote", |
| 124 | + "android.webkit;WebResourceRequest;true;onReceivedHttpError;;;Parameter[1];remote", |
| 125 | + "android.webkit;WebResourceRequest;true;onSafeBrowsingHit;;;Parameter[1];remote", |
| 126 | + "android.webkit;WebResourceRequest;true;shouldInterceptRequest;;;Parameter[1];remote", |
| 127 | + "android.webkit;WebResourceRequest;true;shouldOverrideUrlLoading;;;Parameter[1];remote" |
| 128 | + ] |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +private class WebkitSummaryModels extends SummaryModelCsv { |
| 133 | + override predicate row(string row) { |
| 134 | + row = |
| 135 | + [ |
| 136 | + "android.webkit;WebResourceRequest;true;getRequestHeaders;;;Argument[-1];ReturnValue;taint", |
| 137 | + "android.webkit;WebResourceRequest;true;getUrl;;;Argument[-1];ReturnValue;taint" |
| 138 | + ] |
| 139 | + } |
| 140 | +} |
0 commit comments