Nexus Void AI Research
Secret Scanning, Hardcoded Secrets, Credential Leak, AppSec, ARGUS, DevSecOps
How to Find and Fix Hardcoded Secrets in Your Code
How to find hardcoded secrets in code and Git history, what to do when a key leaks, which secrets to rotate first, and gitleaks vs GitHub secret scanning.
To find hardcoded secrets in code, scan your repositories, your Git history and every new pull request for patterns that look like credentials (API keys, tokens, passwords, private keys), then verify which ones are real and live. For any real secret that reached Git, rotate it at the provider first, then move it into a secrets manager. Deleting the line isn't enough: the value stays in history.
Last updated 31 October 2026.
Hardcoded secrets are tracked as CWE-798: Use of Hard-coded Credentials, and they're among the most damaging findings because a single leaked key can hand an attacker your cloud account, database or a paid third-party service. They leak constantly and quietly: into source files, config, test fixtures, notebooks, CI logs and commit history, and especially into code written quickly with AI assistants. Attackers scan public and breached repositories for them, so detection speed limits the damage. This guide sits in our software supply chain security cluster.
Where do hardcoded secrets usually hide?
Not just in obvious .env files. Any place a developer touched a credential to make something work is a candidate.
Location | Example secret | Why it's missed |
|---|---|---|
Source and config files | Cloud or SaaS API keys | Pasted "just for a quick test" |
Frontend bundles | Keys shipped to the browser | Looks like normal config in a JavaScript framework |
Infrastructure as code | Database passwords, tokens | Treated as config, not code |
Test fixtures and mocks | Sandbox keys reused in production | Assumed to be fake |
Notebooks | Keys in cell outputs | Outputs are committed with the notebook |
Git history | Keys deleted in a later commit | Still retrievable from earlier commits and clones |
CI/CD logs | Variables echoed to output | Logs are readable by more people than the code |
How do you detect hardcoded secrets?
Use three layers, from earliest to latest:
Pre-commit hooks on developer machines, so a key is blocked before it's ever committed.
Pull request scanning on every change, so anything that slips past a hook is caught before it merges. This is the layer you can enforce for the whole team.
Full history scans of every repository, run once now and periodically after, to find keys committed before you started scanning.
Good scanners combine high-signal patterns for known key formats (AWS, Stripe, GitHub, Slack and so on) with entropy analysis to catch generic tokens. The best also check whether a found key still works, so you rotate live credentials first. GitHub's own secret scanning covers many provider formats; open-source tools such as gitleaks and TruffleHog run anywhere. For a comparison of dedicated secret scanners, see GitGuardian alternatives.
What should you do when a secret leaks?
Treat it as an incident, not a code cleanup. In order:
Rotate or revoke the secret at the provider, now. This is the step that actually stops the risk.
Check the provider's logs for use of the old key since it was committed.
Remove it from code and load it from a secrets manager or environment injection instead, following the OWASP Secrets Management Cheat Sheet.
Purge it from Git history if the repository is public or widely shared, using GitHub's guide to removing sensitive data from a repository. History rewriting doesn't reach existing clones and forks, which is why step 1 comes first.
Add scanning to the pull request so the same mistake is caught next time.
Which secrets matter most?
Secret type | Blast radius if leaked | Rotate how fast |
|---|---|---|
Cloud provider keys (AWS, GCP, Azure) | Your whole infrastructure and bill | Immediately |
Database credentials | All customer data | Immediately |
Payment provider keys (live mode) | Money movement, customer payment data | Immediately |
Source control and CI tokens | Your code and deployment pipeline | Immediately |
Third-party SaaS API keys | That service's data and quota | Same day |
Test or sandbox keys | Usually limited; check they aren't reused in production | When convenient |
Why do AI coding assistants increase secret leaks?
Fast, high-volume generation and quick test snippets raise the chance a key gets pasted into code or shipped to the frontend, and agents that can read your files may copy secrets into new places. Per-pull-request scanning matters more as AI-written code grows. Our vibe coding security checklist covers this alongside other common mistakes in AI-built apps.
How ARGUS finds hardcoded secrets
ARGUS scans every repository and pull request for hardcoded secrets with gitleaks plus entropy checks, and shows whether each one is live, rotated or a test key, so you rotate the ones that matter first. Secrets appear in the same ranked list as vulnerable dependencies and insecure code, and a required check can stop a pull request that introduces a live key from merging. Rotation at the provider stays a human step, because only you can safely cycle a production credential. See the specialist agents behind each check.
Frequently asked questions
Why isn't deleting the line enough?
Because Git keeps history. The secret is still retrievable from earlier commits, clones and forks, so it must be rotated at the provider and, ideally, purged from history.
What's the difference between gitleaks and GitHub secret scanning?
GitHub secret scanning is built into GitHub and covers many provider token formats, with some providers notified automatically when their tokens leak in public repositories. Gitleaks is an open-source scanner you can run anywhere, including pre-commit and in any CI system, with custom rules. Many teams use both: a local hook plus pull request scanning.
What is the difference between secret scanning and SAST?
Secret scanning looks for credentials committed into code; SAST looks for insecure code patterns such as injection. Both belong in the pull request, and many tools run them together.
Are secrets in a private repository safe?
Safer, not safe. Private repositories are read by every employee, contractor, CI system and integration with access, and get copied into clones and backups. Treat any committed secret as exposed.
Our read
Hardcoded secrets are the cheapest breach an attacker can hope for and the cheapest to prevent, which is why catching them at the pull request is one of the highest-return controls a startup can add. The failure mode is treating a found secret as a code cleanup instead of an incident: the moment a credential is committed, consider it burned and rotate it.
Related reading: How to secure a CI/CD pipeline on GitHub Actions · How to detect malicious npm packages · CTO guide to securing a startup codebase · How to secure third-party API integrations
DATA SOURCES
OWASP Secrets Management Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html ; CWE-798 Use of Hard-coded Credentials: https://cwe.mitre.org/data/definitions/798.html ; GitHub Secret Scanning docs: https://docs.github.com/code-security