JavaScript is switched on for a WebView

tx0/java:webview-javascript-enabledstrictwarningsecurity, cwe-79

What it finds

A WebView with JavaScript enabled runs the scripts of every page it loads, so a page from an untrusted source or a response modified on the way can act inside the app (CWE-79). Apps that show only their own content can leave it off, as the Android security guidance advises.

Reported is setJavaScriptEnabled(true).

From the rule's source, webview_javascript_enabled.rs.

Example from the rule's tests
import android.webkit.WebSettings; class Browser {  void setup(WebSettings settings) {    settings.setJavaScriptEnabled(true);tx0 reports: runs the scripts of every page    settings.setJavaScriptEnabled(false);  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:webview-javascript-enabled" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:webview-javascript-enabled] reason="..."

tx0 explain tx0/java:webview-javascript-enabled shows the same in the terminal. Found a false positive? Report it.