Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated
Hardcoded secrets are passwords or keys written directly into a program. MITRE's CWE-798 describes the weakness as a product in which credentials such as passwords or cryptographic keys are embedded as fixed values.
How do hardcoded secrets work?
Imagine a spare key to a building printed in the corner of a catalog handed out to residents. Anyone who gets the catalog can learn the shape of the key.
CWE-798 sorts this weakness into two forms. In one, the product checks users with a fixed built-in password. In the other, a front-end product embeds the credentials it uses to connect to a back-end system. The OWASP Mobile Top 10 explains that an app is vulnerable if it embeds credentials in its code or configuration files. Whoever finds them may be able to reach important functions or back-end systems without authorization.
The core of the countermeasure is to keep credentials outside the code. CWE-798 lists putting them in configuration files or databases that are encrypted and have restricted permissions. In its PHP example, it lists environment variables or a secrets-management service. To start from the outside view of your own site, use the free URL check.
Why do hardcoded secrets matter?
Apps and programs are distributed, or pass through many hands. If a key is written in the code, then even if you meant to limit who holds it, in practice everyone who can view the code holds it.
Another problem is that it is hard to notice later, even if it was convenient when written. A value written for testing during development can remain in production as it is. When you try to change the key, you have to rebuild the program and distribute it again, which takes effort.
As countermeasures, the OWASP Mobile Top 10 lists not embedding credentials in the app, using tokens that can be revoked, and rotating API keys and similar secrets regularly. Ask your development contractor to check once where the keys you use are kept.
Related terms
- Insecure data storage: a flaw in which important information is stored on a device in plain view.
Next step
Points to check are on the hardcoded secrets vulnerability page. If you want to settle where keys are kept and how they are rotated, contact us. The free URL check sees only the public side of your site.
Frequently asked questions
Why is it dangerous to write secrets directly into a program?
Because someone who gets hold of the program may be able to read them from inside it. The OWASP Mobile Top 10 explains that an app is vulnerable if it embeds credentials in its code or configuration files.
If we stop writing them directly, where should they go?
Outside the code. CWE-798 lists configuration files or databases that are encrypted and have restricted permissions, and in its PHP example it lists environment variables or a secrets-management service. Also check the permission settings on the place where they are kept.
Frequently asked questions
Why is it dangerous to write secrets directly into a program?
Because someone who gets hold of the program may be able to read them from inside it. The OWASP Mobile Top 10 explains that an app is vulnerable if it embeds credentials in its code or configuration files.
If we stop writing them directly, where should they go?
Outside the code. CWE-798 lists configuration files or databases that are encrypted and have restricted permissions, and in its PHP example it lists environment variables or a secrets-management service. Also check the permission settings on the place where they are kept.