diff --git a/java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.qhelp b/java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.qhelp new file mode 100644 index 00000000000..cb80e92eab1 --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.qhelp @@ -0,0 +1,57 @@ + + + +

+ File access in an Android WebView can expose the device's file system to + the JavaScript running in the WebView. If there are vulnerabilities in the + JavaScript, file access may allow an attacker to access or steal the + user's data. +

+
+ + +

When possible, you should disallow file access by setting the following settings to false:

+ + +
+ + +

In the following (bad) example, the WebView is configured with the settings + which would allow local file access.

+ + + +

In the following (good) example, the WebView is configured to disallow file access.

+ + + +
+ + +
  • + Android documentation: WebSettings.setAllowFileAccess. +
  • +
  • + Android documentation: WebSettings.setAllowFileAccessFromFileURLs. +
  • +
  • + Android documentation: WebSettings.setAllowUniversalAccessFromFileURLs. +
  • +
  • + File access from URLs is enabled for WebView: File access for URLs is enabled for WebView. +
  • +
  • + File access is enabled for WebView: File access is enabled for WebView. +
  • +
  • + Universal file access from file URLs is enabled for WebView: Universal file access from file URLs is enabled for WebView. +
  • +
    + +
    diff --git a/java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.ql b/java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.ql new file mode 100644 index 00000000000..e34d502f3fa --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-200/AndroidWebViewSettingsFileAccess.ql @@ -0,0 +1,18 @@ +/** + * @name Android WebSettings file access + * @kind problem + * @id java/android-websettings-file-access + * @problem.severity warning + * @security-severity 6.5 + * @precision high + * @tags security + * external/cwe/cwe-200 + */ + +import java +import semmle.code.java.frameworks.android.WebView + +from MethodAccess ma +where ma.getMethod() instanceof CrossOriginAccessMethod +select ma, "WebView setting $@ may allow for unauthorized access of sensitive information.", ma, + ma.getMethod().getName() diff --git a/java/ql/src/Security/CWE/CWE-200/WebViewFileAccessSafe.java b/java/ql/src/Security/CWE/CWE-200/WebViewFileAccessSafe.java new file mode 100644 index 00000000000..6002888cba1 --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-200/WebViewFileAccessSafe.java @@ -0,0 +1,5 @@ +WebSettings settings = view.getSettings(); + +settings.setAllowFileAccess(false); +settings.setAllowFileAccessFromURLs(false); +settings.setAllowUniversalAccessFromURLs(false); diff --git a/java/ql/src/Security/CWE/CWE-200/WebViewFileAccessUnsafe.java b/java/ql/src/Security/CWE/CWE-200/WebViewFileAccessUnsafe.java new file mode 100644 index 00000000000..6c17d66c3b0 --- /dev/null +++ b/java/ql/src/Security/CWE/CWE-200/WebViewFileAccessUnsafe.java @@ -0,0 +1,5 @@ +WebSettings settings = view.getSettings(); + +settings.setAllowFileAccess(true); +settings.setAllowFileAccessFromURLs(true); +settings.setAllowUniversalAccessFromURLs(true);