A string literal contains a PEM private key
What it finds
A private key in the source is readable by everyone with access to the repository, its history and every build made from it, and cannot be rotated without a code change.
Reported are string and template literals that contain the header of a PEM private key, such as -----BEGIN RSA PRIVATE KEY-----, followed by key data. A header alone, as in code that parses keys, is left alone.
From the rule's source, private_key_literal.rs.
export const key = "-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAu1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw\n-----END RSA PRIVATE KEY-----";tx0 reports: contains a private keyexport const header = "-----BEGIN PRIVATE KEY-----";export const certificate = "-----BEGIN CERTIFICATE-----\nMIIEowIBAAKCAQEAu1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw\n-----END CERTIFICATE-----"; 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/ts:private-key-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/ts:private-key-literal] reason="..."tx0 explain tx0/ts:private-key-literal shows the same in the terminal. Found a false positive? Report it.