certificate_check_switched_off
Reports a callback that accepts every certificate the TLS check refused. Remove it, or trust only your own proxy in debug builds.
- Tier
- blocking
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- none
- Security class
- CWE-295 · mobile risk M5 (insecure communication) · severity 8.1
What it reports
Section titled “What it reports”A callback that accepts every certificate that the TLS check refused, where it is given that decision:
- the
badCertificateCallbackof anHttpClientofdart:io, set by an assignment or in a cascade, also inside an override ofHttpOverrides.createHttpClientand in thecreateHttpClient(or the olderonHttpClientCreate) of dio’sIOHttpClientAdapter; - the
onBadCertificateofconnect,startConnectandsecureofSecureSocketandRawSecureSocket; - the
onSslAuthErrorof a webview_flutterNavigationDelegatewhose callback callsproceed()on the error it is given, as a statement of its own body or as its expression.
A callback accepts every certificate when it is a function literal, or a tear-off of a function or method that the same file declares, whose every return (at least one), or whose expression body, folds to true from literals alone: true, 1 == 1, !false.
It does not report:
- a callback that reads its certificate, its host or its port (pinning, a proxy on a known host), or that may return
false, such as one that accepts only after testing the host:if (host == '192.168.1.5') return true; return false;; - dio’s
validateCertificate, which checks a certificate after the TLS check accepted it; - a tear-off of a function of another file;
proceed()under a condition;- debug-only code: under
kDebugModeor!kReleaseMode, a conditional on them, afterif (kReleaseMode) return;, or inside anassert; - the test side.
A callback that accepts every certificate is reported wherever the connection goes, to a local address too: a device of the local network with a certificate of its own is trusted by its certificate, not by its host. A profile build (kProfileMode) runs on devices, and is judged.
A callback that only debug builds install through another function, such as an HttpOverrides subclass set as HttpOverrides.global under kDebugMode elsewhere, is reported at the callback. Move the condition into the callback, or keep it with a justified suppression.
The callback is asked only when the TLS check has refused the certificate: the host is not who it says it is, or the certificate is expired, self-signed or for another name. Accepting it there accepts whoever intercepts the connection, such as a public Wi-Fi, a compromised router or a proxy, and lets them read and change every request and answer.
The usual reason, trusting your own proxy while debugging, needs neither every certificate nor a release build.
Example
Section titled “Example”HttpClient client() => HttpClient()..badCertificateCallback = (cert, host, port) => true;HttpClient client() { final client = HttpClient(); if (kDebugMode) { client.badCertificateCallback = (cert, host, port) => host == 'proxy.lan' && cert.sha1.toString() == _proxyFingerprint; } return client;}Rule parameters
Section titled “Rule parameters”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. |
Security class
Section titled “Security class”In SARIF, the rule’s descriptor carries the tags security, external/cwe/cwe-295 and external/owasp-mobile-2024/m5, and the security-severity 8.1, so code scanning lists its violations as security alerts of high severity. No other report changes.
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Only the device lab's proxy, whose builds never ship.// ignore: assay/certificate_check_switched_off// ignore_for_file: assay/certificate_check_switched_off silences it in a whole file, and // ignore: certificate_check_switched_off without the prefix works too. See Suppressions, and Marking a result as reviewed for a finding you reviewed and found safe.