Course contentsShow
← Security
Lesson 1252 of 3,05225. Application Security - Secure CodingFree lesson

Understanding Hardcoded Secrets and Their Risks

Learn what constitutes hardcoded secrets, why they're dangerous, and common locations where secrets are accidentally committed.

Understanding Hardcoded Secrets and Their Risks

You'll learn what hardcoded secrets are, why they pose critical security risks, and where developers commonly leave them exposed.

What Are Hardcoded Secrets?

Hardcoded secrets are sensitive credentials—such as passwords, API keys, encryption keys, database connection strings, or tokens—that developers embed directly into source code instead of storing them securely elsewhere. Think of it like writing your house key's combination on a sticky note attached to your front door: convenient for you, but accessible to anyone who looks.

Why Are They Dangerous?

When secrets live in source code, they:

  • Travel everywhere the code goes: from developer machines to version control repositories, CI/CD pipelines, production servers, and backup systems
  • Remain in version history forever: even if deleted later, Git and other version control systems preserve historical commits
  • Become accessible to anyone with code access: developers who leave, contractors, or attackers who breach your repository
  • Enable complete system compromise: a leaked database password or AWS key can grant unlimited access to critical infrastructure

Common Locations Where Secrets Accidentally Appear

Developers frequently hardcode secrets in:

  • Configuration files committed to Git
  • Example or test files meant as templates
  • Comments explaining authentication flows
  • Environment setup scripts
  • Mobile app source code (easily reverse-engineered)
  • Log files and error messages
  • Public GitHub repositories (accidentally made public)

Automated scanners constantly crawl public repositories hunting for these exposed credentials, often exploiting them within minutes of exposure.

Key Takeaway: Hardcoded secrets are credentials embedded directly in source code—a critical vulnerability because code is widely distributed, version-controlled, and accessible to many people, making secrets easily discoverable and permanently archived.