Hard-coded secrets are passwords, keys and tokens written directly into a program's code or settings files, instead of being kept in a protected store. A secret, in software, is anything a program uses to prove who it is to another system. Examples are a database password, a cloud access key, and an API key, the long string of characters that a service gives a customer's program so that it can recognise that program.
Here is how a secret ends up in the code. A developer needs the program to reach a database, and types the password into the code to get it working. The code is then saved to a repository, the shared store of the team's code. The repository keeps every old version, so deleting the line later does not remove the password from the history. The code is then copied many times: to other developers, to contractors, into builds and sometimes into a public repository. If the program is a phone app, the secret is packed inside the app file on every customer's phone. Anyone who reads any of these copies can read the secret. Attackers run automated searches of public code sites, and they can find a new key within minutes.
The fix is to keep secrets out of the code. Secrets management keeps them in a vault. The program asks the vault for the secret when it starts, using its own identity, and the vault changes the secret regularly. Secret scanners, often part of static application security testing tools, check each change to the code and block one that contains a secret.
Take, for example, a developer who leaves a cloud access key in a script and pushes it to a public repository. Within hours, someone can use the key to start servers on the company's account, and the bill arrives at the end of the month.
Consider a shopping app for phones with a payment provider's key inside it. Anyone can unpack the app and read the key, which is why mobile app shielding and outside-in scans by external attack surface management look for exactly this.
Say a company sells home routers that all ship with the same administrator password written into the firmware. One leaked password then opens every router of that model.
How is a hard-coded secret different from a stolen employee password? An employee's login usually asks for a second check, such as an OTP. A program's secret usually has no second check, often has wide permissions and is rarely changed. So one leaked key can open a whole database. Programs that log in this way are non-human identities.
Appears in
- Privileged access management (PAM)↗ Enterprise cybersecurityPrivileged access management replaces hard-coded admin passwords in scripts with passwords fetched from its vault at run time.
- Secrets management↗ Enterprise cybersecuritySecrets management lets a program fetch its database password when it starts, so the password is never written into the code.
- Static application security testing (SAST)↗ Enterprise cybersecuritySAST software reads the source code and flags a password or API key typed directly into it.
- Mobile app shielding↗ Enterprise cybersecurityMobile app shielding hides the API keys inside a phone app, so someone who takes the app apart cannot read them.
- External attack surface management (EASM)↗ Vulnerability and exposure managementEASM software finds a company's code left public on the internet and flags any passwords or keys inside it.
- Dark-web monitoring↗ Vulnerability and exposure managementDark-web monitoring alerts the company when its API keys or passwords appear for sale on criminal forums.