Skip to content

cleartext_request

Reports an http or ws URL to a host that is not local, given to a call that sends a request or loads a page. Use https or wss.

Tier
blocking
Scope
Dart
Lowest preset
recommended
Fix
none
Security class
CWE-319 · mobile risk M5 (insecure communication) · severity 7.4

An http URL (or ws for a web socket) to a host that is not local, given to a call that sends a request or loads a page. The message names the host. The calls are:

  • package:http: get, post and its other functions, the same methods of a Client, and the constructors of Request, StreamedRequest and MultipartRequest;
  • dart:io: the requests of HttpClient, and WebSocket.connect;
  • dio: the request methods of Dio, and its baseUrl;
  • webview_flutter’s WebViewController.loadRequest; Flutter’s Image.network and NetworkImage;
  • url_launcher’s launchUrl and launchUrlString, only with mode: LaunchMode.inAppWebView.

The URL counts where the code writes its scheme and its whole host: in a literal, a constant or a final local, also inside Uri.parse or at the start of an interpolation such as '$baseUrl/orders'.

It does not report:

  • a local host: localhost, 127.0.0.1, the private networks (with the Android emulator’s 10.0.2.2), a name of one label, names below local, example.com;
  • a host named in allowed_hosts;
  • a host not written whole: 'http://$host/';
  • debug-only code, and the test side.

On plain HTTP, whoever is on the network between the device and the host (the café’s Wi-Fi, a compromised router, the operator) reads every request and answer, cookies and tokens among them. They can also change them: inject script into a page, swap a download, alter a price.

Android (from API 28) and iOS block cleartext by default. So such a call often fails only in production, or works only because a platform file allows it, which cleartext_traffic_allowed reports.

Violating
final response = await http.get(Uri.parse('http://api.shop.dev/orders'));
Corrected
final response = await http.get(Uri.parse('https://api.shop.dev/orders'));

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

Rule parameter Default Effect
allowed_hosts [] Further hosts reached over plain HTTP on purpose, beside the local hosts. *.lan names every host below lan.
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.
assay:
rules:
cleartext_request:
allowed_hosts: [printer.lan]

Write why on the line directly above the suppression:

// The kiosk's local status page, served by its own firmware over HTTP only.
// ignore: assay/cleartext_request

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

All cases
  • package:http: its functions get, post, put, patch, delete, head, read, readBytes; the same methods of a Client (IOClient, BaseClient and every other client); the constructors of Request, StreamedRequest and MultipartRequest;
  • dart:io: getUrl, postUrl, putUrl, patchUrl, deleteUrl, headUrl, openUrl of HttpClient; its get, post, put, patch, delete, head and open by host, which always speak plain HTTP (the host is judged); WebSocket.connect;
  • dio: the request methods of Dio by an absolute path or a Uri, BaseOptions(baseUrl: …) and an assignment to baseUrl of its options;
  • webview_flutter’s WebViewController.loadRequest; Flutter’s Image.network and NetworkImage;
  • url_launcher’s launchUrl and launchUrlString only with mode: LaunchMode.inAppWebView.

The URL counts where the code writes its scheme and its whole host:

  • a string literal, or adjacent ones;
  • an interpolation or a + of texts whose start holds both: '$base/users' where base is such a text;
  • a constant, or a local that keeps its value, whose whole value is a scheme and a complete host, at the start of an interpolation or a +, whatever follows it: '$baseUrl$endpoint', baseUrl + endpoint with baseUrl = 'http://api.shop.com';
  • a constant in any library, read from its initializer: static const baseUrl = 'http://…';
  • a local variable that is final, or that its function does not write again;
  • Uri.parse or Uri.tryParse of one of these, Uri.http('<host>', …), Uri(scheme: 'http', host: '<host>'), and a local variable of such a Uri.

A host is complete when it is a dotted name whose last label begins with a letter, an IPv4 address of four numbers, an IPv6 address in brackets, or any host followed by a port: 'http://printer:8080'.

  • a local host: localhost and the names below it, 127.0.0.0/8, ::1, 0.0.0.0; the private networks 10/8 (with the Android emulator’s 10.0.2.2), 172.16/12 and 192.168/16; link-local 169.254/16, fc00::/7, fe80::/10; a name of one label; names below local, home.arpa and internal; the reserved example.com, example.net and example.org and their subdomains, *.example, *.test, *.invalid;
  • a host named in allowed_hosts;
  • a host not written whole: 'http://$host/'; a constant whose host may run on in what follows it ('http://', 'http://api.', 'http://printer', 'http://192.168.1', 'http://admin:' before a password); a host written in the literal itself before what follows ('http://api.shop.com$path');
  • a URL that goes to no such call, such as a link shown as text;
  • url_launcher in the modes of a browser, whose policy applies;
  • a constant whose initializer chooses by the build mode, kReleaseMode ? 'https://…' : 'http://…', which is never taken for one of its sides;
  • debug-only code, and the test side.

A host of allowed_hosts is compared as a local host is: without regard to case, with or without a final dot, and an IPv6 address with or without its brackets (2001:db8::1 names http://[2001:db8::1]/).

A host is judged by its name: a public name that resolves to a private address is reported. Add it to allowed_hosts.

In SARIF, the rule’s descriptor carries the tags security, external/cwe/cwe-319 and external/owasp-mobile-2024/m5, and the security-severity 7.4. No other report changes. See Security.