Skip to main content

redact_secrets

Function redact_secrets 

Source
pub fn redact_secrets(command: &str) -> (String, bool)
Expand description

Replace secrets in a command line with *** before it is stored.

Covers mysql -pSECRET, --password=… (and --token, --secret, --api-key), NAME=value assignments whose name contains PASSWORD, PASS, TOKEN, SECRET, KEY, CREDENTIAL (PGPASSWORD, MYSQL_PWD, GITHUB_TOKEN, AWS_SECRET_ACCESS_KEY, …), user:pass@ in URLs, Authorization: / apikey:-style headers, curl -u user:pass, docker login -p …, aws configure set aws_secret_access_key …, npm config set …:_authToken …, JSON Web Tokens (eyJ….eyJ….…), and AWS (AKIA…), GitHub (ghp_…), GitLab (glpat-…), npm (npm_…), Slack (xoxb-…), Stripe (sk_live_…, rk_live_…) and sk-… keys.

Returns the redacted text and whether anything was replaced. This is a best-effort safety net, not a guarantee: a secret passed positionally (tool login s3cr3t) cannot be recognised.