WSWhat Scene?

Learn · Development dos and don'ts

Why should you never put passwords or API keys in code?

Because code gets shared, copied, and stored in version control, so a password or API key written into it can leak to anyone with access, including the public if the code ever goes online. Leaked keys get abused within minutes by automated bots. Secrets belong in environment variables or a secrets manager, never in the code itself.

This is one of the most common serious mistakes. Developers hardcode a key to test something, forget it, and push it to a public repository. Bots scan those constantly, and a leaked cloud key can run up huge bills or expose customer data before you notice.

The rule is simple: keep secrets out of code, load them from a secure store at runtime, and if one ever leaks, rotate it immediately. Treat every credential as if it will eventually be seen by the wrong person.

Updated July 2026

Related

Want this built, not just explained?