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
What it reports
Section titled “What it reports”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,postand its other functions, the same methods of aClient, and the constructors ofRequest,StreamedRequestandMultipartRequest; dart:io: the requests ofHttpClient, andWebSocket.connect;- dio: the request methods of
Dio, and itsbaseUrl; - webview_flutter’s
WebViewController.loadRequest; Flutter’sImage.networkandNetworkImage; - url_launcher’s
launchUrlandlaunchUrlString, only withmode: 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’s10.0.2.2), a name of one label, names belowlocal,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.
Example
Section titled “Example”final response = await http.get(Uri.parse('http://api.shop.dev/orders'));final response = await http.get(Uri.parse('https://api.shop.dev/orders'));Rule parameters
Section titled “Rule parameters”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]Suppressing it
Section titled “Suppressing it”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.
Details
Section titled “Details”All cases
The calls in full
Section titled “The calls in full”- package:http: its functions
get,post,put,patch,delete,head,read,readBytes; the same methods of aClient(IOClient,BaseClientand every other client); the constructors ofRequest,StreamedRequestandMultipartRequest; dart:io:getUrl,postUrl,putUrl,patchUrl,deleteUrl,headUrl,openUrlofHttpClient; itsget,post,put,patch,delete,headandopenby host, which always speak plain HTTP (the host is judged);WebSocket.connect;- dio: the request methods of
Dioby an absolute path or aUri,BaseOptions(baseUrl: …)and an assignment tobaseUrlof its options; - webview_flutter’s
WebViewController.loadRequest; Flutter’sImage.networkandNetworkImage; - url_launcher’s
launchUrlandlaunchUrlStringonly withmode: LaunchMode.inAppWebView.
Where the URL counts
Section titled “Where the URL counts”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'wherebaseis 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 + endpointwithbaseUrl = '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.parseorUri.tryParseof one of these,Uri.http('<host>', …),Uri(scheme: 'http', host: '<host>'), and a local variable of such aUri.
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'.
What it does not report
Section titled “What it does not report”- a local host:
localhostand the names below it,127.0.0.0/8,::1,0.0.0.0; the private networks10/8(with the Android emulator’s10.0.2.2),172.16/12and192.168/16; link-local169.254/16,fc00::/7,fe80::/10; a name of one label; names belowlocal,home.arpaandinternal; the reservedexample.com,example.netandexample.organd 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.
Rule parameters in detail
Section titled “Rule parameters in detail”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.
Security class
Section titled “Security class”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.