secret_in_log
Reports a secret, such as a password or a token, passed to a log call. Log a fact about it instead, such as whether it is set.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- none
- Security class
- CWE-532 · mobile risk M9 (insecure data storage) · severity 4.3
What it reports
Section titled “What it reports”An argument of a log call that holds a secret as it is.
- A secret is a text read by a credential name:
password,accessToken,session.refreshToken,apiKey, … (the names ofhard_coded_credential). It counts given directly, interpolated ('Signed in with $accessToken') or joined ('key ' + apiKey), and through??,!, a cast,toString()and final locals. - A log call is one of:
printanddebugPrint;- a function or method named
log; - any method of a class named
Loggeror ending inLogger; - the functions and methods you list in
logging_calls.
Every argument counts, named ones too: log('failed', error: token). The message names the kind of secret. Where avoid_print is on, a print of a secret gets both: avoid_print at print, this rule at the argument.
It does not report:
- what tells nothing of the secret: its
length,isEmpty,isNotEmpty,== null,!= null,hashCode; - a secret passed to your own code first, such as
mask(token); - a value that is not text, whatever its name: a parser’s token, dio’s
CancelToken; - a constant:
Keys.accessToken, the name of a key, a literal; - a push or page token:
fcmToken,nextPageToken. A value named justtokenis silent too when the literal text right before it names it so, in an interpolation, a+or adjacent strings:'FCM Token: $token','Got APNs token: ${token}','FCM Token: ' + token.'Signed token: $token'and'token: $accessToken'are still reported. - dio’s
LogInterceptor, which by default prints only where assertions run, in debug builds; - debug-only code, such as code under
kDebugMode, and tests.
A secret passed to package:logger is reported, though its default filter drops records in release builds: a project may set a filter that keeps them.
Logs travel further than you think. On Android, the debugging tools read logcat, and so do other apps on older versions. Crash reporters and support tools collect logs and send them to servers and to people who should never see a user’s password, or a token that opens their account. A log line outlives the session it describes.
Example
Section titled “Example”debugPrint('Signed in with ${session.accessToken}');debugPrint('Signed in; token set: ${session.accessToken.isNotEmpty}');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. |
logging_calls |
[] |
More functions and methods that write their arguments to a log, such as the methods of your own logger. |
assay: rules: secret_in_log: logging_calls: [trace]Security class
Section titled “Security class”In SARIF, the rule’s descriptor carries the tags security, external/cwe/cwe-532 and external/owasp-mobile-2024/m9, and the security-severity 4.3. No other report changes. See Security.
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// The token of the demo account, which is public on the store page.// ignore: assay/secret_in_log// ignore_for_file: assay/secret_in_log silences it in a whole file, and // ignore: secret_in_log without the prefix works too. See Suppressions.