hardcoded-secret
A secret written into the code.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule hardcoded-secret - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
A key, salt, token, or password is a literal in the code, so anyone who can read the code, or a copy of it, can read it, and changing it means changing the code. Read it from the environment or the framework's encrypted credentials.
The fix, as Ur suggests it: read the secret from the environment or credentials.
For agents
Never write a secret into the code; read it from the environment or encrypted credentials.
Example
config/initializers/secret_token.rbApp.config.secret_key_base = "2f1d90a26236c3245d96f5"
$ ur scan --rule hardcoded-secret
warning[hardcoded-secret]: `secret_key_base` is set to a literal, which anyone with the code can read
--> ./config/initializers/secret_token.rb:1:1 module's top level
= hint: read the secret from the environment or credentials
= see: CWE-798: Use of Hard-coded Credentials, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/798.html
scanned 1 file (no framework recognized)
hardcoded-secret: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
CWE-798: Use of Hard-coded Credentials, MITRE (2024-11-19).