New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: Query for detecting enabling Javascript in Android WebSettings #11238
base: main
Are you sure you want to change the base?
Java: Query for detecting enabling Javascript in Android WebSettings #11238
Conversation
|
QHelp previews: java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.qhelpAndroid WebView JavaScript settingsEnabling JavaScript in an Android WebView allows for the running of JavaScript code in the context of the running application. This opens the possibility for cross-site scripting if the attacker can inject arbitrary JavaScript. For example, if your application's WebView allows for visitng web pages which you do not trust, it is possible for an attacker to lead the user to a page which loads malicious JavaScript. You can enable or disbale Javascript execution using the RecommendationIf Javascript does not need to be enabled, call If JavaScript is necessary, only load content from trusted servers using encrypted channels, such as HTTPS with certificate verification. ExampleIn the following (bad) example, a WebView has JavaScript enabled in its settings. WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);In the following (good) example, a WebView explicitly disallows JavaScript execution. WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(false);References
|
| <p> | ||
| Enabling JavaScript in an Android WebView allows for the running of JavaScript | ||
| code in the context of the running application. This opens the possibility for a | ||
| man-in-the-middle attack, where the attacker can inject arbitrary JavaScript. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attack vector isn't only a MitM attack: if the application loads untrusted content in the WebView, attackers could provide malicious JavaScript to be executed as well.
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.ql
Outdated
Show resolved
Hide resolved
java/ql/src/Security/CWE/CWE-079/AndroidWebViewSettingsEnabledJavaScript.ql
Outdated
Show resolved
Hide resolved
| </overview> | ||
|
|
||
| <recommendation> | ||
| <p>If Javascript does not need to be enabled, call <code>setJavaScriptEnabled(false)</code> on the settings of the webview.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention that this is false by default, and thus it would also suffice to not explicitly enable it?
Typos and formatting changes. Co-authored-by: Tony Torralba <atorralba@users.noreply.github.com>
Co-authored-by: Tony Torralba <atorralba@users.noreply.github.com>
Add a query for detecting the enabling of JavaScript execution in Android WebViews.