What Are Hardcoded Secrets in Software, and How Do They Leak? (Explained Clearly) - Security+
Learn what hardcoded secrets are, how they leak through Git history and shipped apps, and why revoking exposed credentials matters more than deleting them.
๐ Master your Security+ skills with Pluralsight here: Pluralsight
Youโll learn what hardcoded secrets are, how passwords and API keys can leak through Git history or shipped apps, and why deleting them from code isnโt enough. This beginner-friendly Security+ guide shows how to prevent leaks with a secrets manager and respond by revoking exposed credentials.
Chapters: 0:00 Intro 0:13 What counts as a hardcoded secret in software? 1:08 Can hardcoded secrets leak from a private repository? 2:20 How do you prevent and respond to hardcoded secrets? 3:30 Outro
Affiliate notice: Some links may earn a commission. Thanks for your support.
Key Takeaways
Hardcoded secrets are live credentials embedded in code, configuration, or shipped software. A reference such as PAYMENTS_TOKEN is not the secret itself.
Deleting a secret from the latest version doesnโt stop it from working. It may still exist in Git history, clones, or shipped apps and container images. Rewriting Git history canโt recall copies others already have.
Revoke an exposed credential at the issuer. Replace it where needed, review audit logs for unexpected activity, and remove the old value from code and affected builds.
Judge the blast radius by what the credential can do, where it works, and how long it remains valid. A read-only test key poses less risk than a production credential that can delete records.
Keep privileged credentials on the backend and retrieve them at runtime using a secrets manager. Prefer short-lived, narrowly scoped credentials, and use secret scanning and push protection as safeguards.
๐ Put your Security+ knowledge into practice with Pluralsight. Build skills in guided labs, get feedback, and use assessments and practice exams to focus your prep.
A database password can disappear from the latest version of your code and still work for anyone who copied it. Thatโs why responding to hardcoded secrets involves two separate jobs: disabling the exposed credential and removing it from the software and its copies.
What are hardcoded secrets in software?
A hardcoded secret is a sensitive value stored directly in source code, a configuration file, or a shipped artifact such as a mobile app or container image. Instead of receiving the credential separately when it needs it, the software carries the value with it.
A fixed maintenance password that a device accepts is an hardcoded credential. A database password that an application uses to connect to another system is an hardcoded credential. MITRE tracks these weaknesses under . It separately catalogs , such as a private signing key embedded in a release tool.
FAQ
Quick answers to the questions people usually ask about this topic.
Is it safe to commit a .env.example file?
Yes, if it contains only variable names, safe defaults, and clearly fake placeholders. For example, PAYMENTS_TOKEN=replace_me shows what developers need to configure without exposing a working token. Check the template for copied production values before committing it.
Can I encrypt a hardcoded secret instead of removing it?
Not if you ship the decryption key alongside it or otherwise give every client what it needs to decrypt it. Encryption at rest can protect a secret when the decryption key is managed separately and available only to authorized workloads. See the OWASP Secrets Management Cheat Sheet for guidance.
Are hardcoded API keys in mobile apps always a security problem?
No. Some providers issue keys specifically for public clients, such as Stripeโs publishable keys. Check the providerโs documentation rather than relying on the label โAPI key.โ If the key grants privileged access, keep it on a trusted backend, not in the app.
What should I do if secret scanning flags a placeholder or test key?
Verify whether the value can authenticate before dismissing the alert. A clearly fake placeholder is safe to keep, but a working test key is still a credential. If it was exposed, assess what it can access and revoke it if it is no longer needed, or rotate it if applications still depend on it. Donโt try an unfamiliar credential against a service you arenโt authorized to access.
Whatโs the difference between leaving a hardcoded secret dormant and revoking it?
A dormant credential is no longer used by the application, but the issuing service may still accept it. Revocation disables it at the issuer, so an old clone or build can still contain the value without granting access.
Where can I get hands-on practice with credential security for Security+?
If youโre ready to move beyond the definitions, try guided security labs on Pluralsight. Use lab feedback and assessments to identify gaps in your understanding of access controls and security operations, then use practice exams to focus your Security+ study.
A live value used to authenticate should not be embedded in code or shipped with the software.
API key
Check the providerโs documentation. Stripeโs publishable keys are intended for client code, while its secret keys belong on the server.
Cryptographic key
A public verification key can be shared. A private signing key or symmetric encryption key must be protected.
Secret reference
An environment-variable name such as PAYMENTS_TOKEN tells the application where to look. It does not contain the token itself.
Hardcoding and exposure are different. A credential can be hardcoded before anyone outside the team sees it. Conversely, an application can retrieve a secret securely at runtime and still leak it by writing the value to a log. For Security+ learners, this distinction matters: the embedded secret is the weakness; a public repository is one place it can be exposed.
How hardcoded secrets leak through Git and shipped software
A Git commit records a version of a project. If you commit a password on Monday and delete it on Tuesday, the password can still be present in Mondayโs commit. Making the repository private limits who can access it, but collaborators and authorized automation may already have copies. If the repository is later made public, those earlier commits can become public too. Even rewriting Git history cannot recall copies that others have already cloned or forked.
Adding .env to .gitignore can help keep an untracked local secrets file out of future commits. It does not stop Git from tracking a file it already tracks, nor does it erase old commits.
A repository can stay private while the software itself exposes the credential. Common examples include:
Browser JavaScript bundled with an API key intended only for a backend.
Mobile apps or firmware that ship the same private key or maintenance password in every copy.
Container images built with credentials that remain in the image or its metadata.
Build and deployment logs that print a sensitive value during an automated job.
Base64 encoding and obfuscation do not make a secret confidential. If every client receives the credential and what it needs to recover it, the credential is no longer confined to a trusted system.
How to judge the blast radius of an exposed secret
The blast radius is the potential damage a credential can cause. Ask what it can read, change, or delete; which environments it works in; and how long it remains valid. A read-only test key for sample data poses a different risk from a production credential that can delete customer records. A package-publishing token presents a different risk again: it could allow someone to publish under the maintainerโs identity.
In 2023, Microsoft disclosed that a URL in a public GitHub repository contained an Azure Storage Shared Access Signature (SAS) token that granted access beyond the research files it was meant to share. Microsoft revoked the token and reported that no customer data was affected. The incident illustrates why even an ordinary-looking download link deserves scrutiny: what matters is the access it grants.
If you discover someone elseโs exposed credential, report where you found it through the designated security channel. Donโt test it or repost the value. Public visibility is not authorization to use it.
How to prevent hardcoded secrets
What to do when a hardcoded secret leaks
Revoke the credential at the issuer. Treat a publicly exposed live credential as compromised. Revocation makes it stop working; rotation replaces it and moves authorized applications to the replacement. If immediate revocation would interrupt a critical service, coordinate a quick cutover and confirm that the old credential is disabled.
Investigate the scope and exposure window. Identify the credential owner, its permissions, the affected environments, and how long it was exposed. Review audit logs for unexpected access or changes. A leak alert indicates possible exposure, not proof that someone used the credential.
Remove the secret and replace affected builds. Switch the software to protected credential delivery, then replace any builds or images that carried the value. Clean up tracked files and consider rewriting Git history where appropriate, but donโt rely on that to erase downloaded copies. If the exposed value was an encryption or signing key, review the data or artifacts affected by that key as well.
Editing Git history changes what people can find in the repository. Revoking the credential changes whether a copy still works. When a live credential leaks, handle that access first.
Practice these skills for Security+
When youโre ready to apply what youโve learned, Pluralsight offers guided security labs and feedback. Use assessments to find gaps in your understanding and practice exams to focus your certification prep.
Store credentials separately from code. Use a secrets manager to control which applications or jobs can retrieve sensitive values at runtime. An environment variable can deliver a secret, but it is not a vault. Writing its value into a Dockerfile or printing it in logs defeats the separation.
Prefer short-lived, narrowly scoped credentials. Where supported, use a workload identity so a running application or automation job can obtain temporary access instead of carrying a permanent key. Keep development and production credentials separate, and grant only the permissions each workload needs.
Keep privileged credentials out of client software. If a browser or mobile app needs a privileged operation, keep the service credential on a trusted backend instead of distributing it with every copy of the client.
Use secret scanning and push protection.Secret scanning flags likely credentials in places such as repository history. Push protection can block some detections before they reach the repository. Both help, but a clean scan does not prove that no secrets are present.
Affiliate link โ I may earn a commission at no additional cost to you.
Jay's Recommendation
Turn understanding into hands-on confidence
You've built the foundations. Pluralsight adds opportunities to practice in guided security labs, get feedback, and check your knowledge with assessments and practice exams, so your next step is more than another video.
๐ Put concepts to workBuild practical skills with guided security labs and feedback.
๐ฏFind your weak spotsUse assessments to focus on what needs more work.
๐Check your understandingUse practice exams to guide your certification preparation.
๐งญGive study sessions directionOrganize further learning with curated paths and progress tracking.