A private key or a service token is written into a string literal
What it finds
A private key block or an access token of a well-known service written into a string literal: anyone who can read the source, its history or the built binary can use it, and it cannot be rotated without a new release. Secrets are read at run time from the environment, a file or a secret store.
Reported are string literals that contain a PEM block whose type ends in PRIVATE KEY, or that hold a token shaped like an AWS access key id (AKIA and 16 upper-case letters or digits), a GitHub token (ghp_, gho_, ghu_, ghs_ or ghr_ and 36 letters or digits), a Slack token (xoxb-, xoxp-, xoxa- or xoxr- followed by digits and dashes), or a Google API key (AIza and 35 more characters). Tokens made of one repeated character, or containing EXAMPLE, are left alone.
From the rule's source, secret_in_literal.rs.
package p const ( awsKey = "AKIAIOSFODNN7ABCDEFG"tx0 reports: this string holds an AWS access key id example = "AKIAIOSFODNN7EXAMPLE" github = "ghp_aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456789"tx0 reports: this string holds a GitHub token marker = "-----BEGIN RSA PRIVATE KEY-----") var key = "-----BEGIN PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEA\n-----END PRIVATE KEY-----"tx0 reports: this string holds a private key 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:
[rules]
"tx0/go:secret-in-literal" = "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/go:secret-in-literal] reason="..."tx0 explain tx0/go:secret-in-literal shows the same in the terminal. Found a false positive? Report it.