A secret key is built from bytes written in the code
What it finds
SecretKeySpec("my-secret-key-12".toByteArray(), "AES") puts the key in the source and in every build, where anyone with either can decrypt. Keys belong in a key store or the environment.
From the rule's source, hardcoded_key.rs.
import javax.crypto.spec.SecretKeySpec fun keys(loaded: ByteArray) { val a = SecretKeySpec("my-secret-key-12".toByteArray(), "AES")tx0 reports: the key is written in the code val b = SecretKeySpec(loaded, "AES")} 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/kotlin:hardcoded-crypto-key" = "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:hardcoded-crypto-key] reason="..."tx0 explain tx0/kotlin:hardcoded-crypto-key shows the same in the terminal. Found a false positive? Report it.