A password, token or secret is written to a log

tx0/kotlin:secret-written-to-logrecommendedwarningsecurity/sensitive-datadepth fastsecurity, cwe-532

What it finds

Logs are kept, shipped and read by more people than the data they describe. A password or token written to them is exposed to all of those. Reported for calls of Android's Log and of the usual logger methods whose arguments name a variable called like a secret. What is only derived from the secret, as token.length, token.isEmpty() or token == null, is left alone.

From the rule's source, secret_in_log.rs.

Example from the rule's tests
fun login(user: String, password: String, accessToken: String, tokenType: String) {    Log.d("auth", "login $user with $password")tx0 reports: password is written to the log    logger.info("token: {}", accessToken)tx0 reports: accessToken is written to the log    logger.info("type: {}", tokenType)    Log.d("auth", "login $user")    Log.d("auth", "token length ${accessToken.length}")    Log.d("auth", "token missing: ${accessToken == null}, blank: ${password.isBlank()}")}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:secret-written-to-log" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:secret-written-to-log] reason="..."

tx0 explain tx0/kotlin:secret-written-to-log shows the same in the terminal. Found a false positive? Report it.