Skip to content

javascript_channel_open_to_any_page

Reports a JavaScript channel on a WebView that runs any script and loads pages from the network, with nothing deciding which pages load. Let only your own pages load, or check in the channel where a message comes from.

Tier
advisory
Scope
Flutter
Lowest preset
recommended
Fix
none
Security class
CWE-749 · mobile risk M8 (security misconfiguration) · severity 6.1

An addJavaScriptChannel(…) on a webview_flutter WebViewController that the same code also:

  • sets to JavaScriptMode.unrestricted (written out or as .unrestricted);
  • has load a page from the network with loadRequest;
  • gives no navigation delegate that decides which pages load.

“The same code” is one cascade, the calls on one local variable or parameter, or the calls on one field inside one function, including a cascade the field or variable is given.

The violation is on the call of addJavaScriptChannel, from the method’s name on. Its message names the channel where the name is a literal.

It does not report:

  • a controller given a NavigationDelegate with onNavigationRequest, or a navigation delegate the code does not make itself, whose decision is not seen;
  • a WebView that loads only the app’s own content (loadFlutterAsset, loadHtmlString, loadFile) and no loadRequest;
  • JavaScript left as it starts, or disabled;
  • debug-only code, and the test side.

A JavaScript channel lets the pages of a WebView call the app’s own Dart code. When the WebView runs any script and can be led anywhere (a link on the page, a redirect, an advertisement, a page that was taken over), every one of those pages can call the channel as the app’s own pages do: read what it answers, start what it starts.

Violating
WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..addJavaScriptChannel('Cart', onMessageReceived: _received)
..loadRequest(page);
Corrected
WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onNavigationRequest: (request) => request.url.startsWith('https://shop.dev/')
? NavigationDecision.navigate
: NavigationDecision.prevent,
),
)
..addJavaScriptChannel('Cart', onMessageReceived: _received)
..loadRequest(page);

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

In SARIF, the rule’s descriptor carries the tags security, external/cwe/cwe-749 and external/owasp-mobile-2024/m8, and the security-severity 6.1. No other report changes.

Write why on the line directly above the suppression:

// The channel only reads the page's height; it answers nothing and starts nothing.
// ignore: javascript_channel_open_to_any_page

// ignore_for_file: assay/javascript_channel_open_to_any_page silences it in a whole file, and // ignore: assay/javascript_channel_open_to_any_page with the prefix works too. See Suppressions.