Skip to content

C0037 cli-secret-flags

Rule: No option takes a secret as its value.

Code C0037 (stable, never reused)
Id cli-secret-flags
Category cli
Source spirit_level
Fix by hand
Needs cargo installed

Level per tier

Tier Level Reason
small warn a candidate: a flag's name is a guess at its purpose, so a human reads each hit; the shell history and the process list both see a value passed on the command line
small-workspace warn a candidate: a flag's name is a guess at its purpose, so a human reads each hit; the shell history and the process list both see a value passed on the command line
medium warn a candidate: a flag's name is a guess at its purpose, so a human reads each hit; the shell history and the process list both see a value passed on the command line
big warn a candidate: a flag's name is a guess at its purpose, so a human reads each hit; the shell history and the process list both see a value passed on the command line
ai off
embedded off
ui off
egui off
units-strict off
units-paranoid off

Parameters

Name Type Default Meaning
words list of strings ["token", "password", "secret", "api-key"] words that mark a flag's long name as holding a secret
safe-suffixes list of strings ["file", "path", "env", "stdin"] a word right after a match that means the flag points at the secret, not holds it

Why

A value passed on the command line sits in the shell history and in ps output for every user on the box. A secret taken that way (--token abc123, --password hunter2) leaks twice over. The right shape reads it from a file, stdin or an environment variable instead.

An option whose long name matches a word in words (token, password, secret, api-key) and takes a value is flagged, unless the next word in its name is in safe-suffixes (file, path, env, stdin): --token-file <PATH> points at where the secret lives, not at the secret itself, and passes.

--token <TOKEN>        <- reported: the token itself as the value
--db-password <PASS>   <- reported
--token-file <PATH>    <- passes: the flag's value is a path

The lint is a candidate: a flag's long name is a guess at what it holds, so it never fails a run at any level and a person reads each hit.

How to fix

Take the secret from --token-file <PATH> (read the file) or from stdin, or read it straight from an environment variable, and drop the flag that takes the secret as a value. List a flag in safe-suffixes when its project uses another indirection word for the same pattern.

Configure

[lints.cli-secret-flags]
level = "deny"
words = ["token", "password", "secret", "api-key"]
safe-suffixes = ["file", "path", "env", "stdin"]
reason = "why this project wants it at this level"

Allow one finding in the code with // spirit-level: allow(cli-secret-flags) <reason> (waivers); the code works there too, as in [lints.C0037].