Skip to content

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

A callback that accepts every certificate that the TLS check refused, where it is given that decision:

  • the badCertificateCallback of an HttpClient of dart:io, set by an assignment or in a cascade, also inside an override of HttpOverrides.createHttpClient and in the createHttpClient (or the older onHttpClientCreate) of dio’s IOHttpClientAdapter;
  • the onBadCertificate of connect, startConnect and secure of SecureSocket and RawSecureSocket;
  • the onSslAuthError of a webview_flutter NavigationDelegate whose callback calls proceed() 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 kDebugMode or !kReleaseMode, a conditional on them, after if (kReleaseMode) return;, or inside an assert;
  • 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.

Violating
HttpClient client() =>
HttpClient()..badCertificateCallback = (cert, host, port) => true;
Corrected(trust only your own debugging proxy, only in debug builds)
HttpClient client() {
final client = HttpClient();
if (kDebugMode) {
client.badCertificateCallback = (cert, host, port) =>
host == 'proxy.lan' && cert.sha1.toString() == _proxyFingerprint;
}
return client;
}

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-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.

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.