A Java object is exposed to the scripts of a WebView

tx0/java:javascript-interfacerecommendedwarningsecurity, cwe-749

What it finds

webView.addJavascriptInterface(bridge, "app") lets every script of every page the view loads call the public methods of bridge, including scripts injected into untrusted content (CWE-749), as the Android documentation of the method warns.

Reported is a call of addJavascriptInterface.

From the rule's source, javascript_interface.rs.

Example from the rule's tests
import android.webkit.WebView; class Bridge {  void setup(WebView view, Object api) {    view.addJavascriptInterface(api, "app");tx0 reports: can call the methods of this object  }}
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:javascript-interface" = "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:javascript-interface] reason="..."

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