On this page, 7 sections
To fix secrets in git history before an audit, find every credential ever committed, rotate each one, and only then decide whether to rewrite history. Deleting a password from the current code does not remove it from git history, and rewriting history does not make a leaked secret safe again. The auditor and the buyer both care about one thing: whether the credential still works.
Why secrets in git history matter to an auditor
Neither SOC 2 nor ISO 27001 has a control that says "no secrets in git". What they have are access control requirements. Under SOC 2 the logical access criteria, mainly CC6.1, require you to restrict access to systems and protect the credentials that grant it. ISO 27001:2022 Annex A has controls on authentication information, secure coding and the use of cryptography. A production password sitting in a repository that every developer, contractor and CI runner can read is an access control failure under all of them.
Git makes this worse than it looks. Every clone of the repository carries the full history. A secret committed eighteen months ago and removed the next day is still in every laptop, every fork, every CI cache and every backup of that repository. If the repository was ever public, even for an afternoon, assume it was scraped. Automated scanners watch public commits for credential patterns continuously.
That is why an assessor rates these findings highly. In a recent engagement, an agentic marketplace platform running SOC 2 and ISO 27001 together, the two critical findings still open at the end of Phase 1 were both credentials committed to source control and kept in git history: a production server password in a deployment workflow and a database connection string in application code. Several high findings were variations on the same theme. None of this was unusual for a small team moving fast. It was simply the most direct path from a leaked laptop to customer data.
Where secrets hide in a typical startup repository
Most teams look in the application code and stop. The places that produce findings are wider than that.
- CI and deployment workflows. Workflow files with a server password, an SSH key or a cloud access key pasted in during a late night deploy. These are high value because they usually grant production access.
- Connection strings in application config. A database URL with the username and password embedded, committed in a settings file "just for now".
- Frontend bundles. API keys and tokens shipped to the browser. These are not only in history; they are served to anyone who loads the page. An external scan in the same engagement found credentials hardcoded in a frontend.
- Infrastructure as code and platform configuration. Terraform variables, container definitions and platform environment settings with plain text values. In the same engagement, two database passwords held in plain text in platform configuration were moved into proper secret storage during Phase 1.
- Test fixtures and notebooks. Real keys used to make a test pass, and data science notebooks with output cells that printed a token.
- Deleted files and old branches. A
.envfile committed once and removed, still reachable through history and any branch that predates the removal.
How to find them
Scan the full history, not just the working tree. A scanner that only reads the current checkout will report a clean repository that is anything but.
- List every repository the organization owns, including archived ones, forks, and personal repositories that held company code. The archived repository nobody remembers is often where the oldest secrets sit.
- Run a history-aware secret scanner across all branches and tags. Open source scanners such as gitleaks and trufflehog both walk commit history and recognize common credential formats. Your source control platform's own secret scanning is worth enabling as well, with push protection so new secrets are blocked at commit time.
- Triage every hit. For each one, record what the credential is, which system it opens, whether it is still valid, and who has had read access to the repository since it was committed. Expect false positives: example values, revoked test keys, hashes. Mark them with a reason rather than deleting them from the list.
- Check the places scanners miss. CI logs, build artifacts, container images and wiki pages copied from the repository. A secret printed in a build log is exposed to everyone who can read the logs.
- Put the results in your findings register with a severity, an owner and a fix-by date. An auditor wants to see that the finding was identified, ranked and closed under your own policy, not that it never existed.
Free weekly email
Get The Compliance Brief every Tuesday
One email a week from Jacob Masse: the security and compliance stories that changed something that week, and what each one means if you sell software to enterprise buyers. Five stories, a take on each, five minutes to read.
Free. Unsubscribe in one click, and replies reach Jacob directly. Read the latest issue or browse the archive.
How to fix them, in the right order
The order matters more than the tooling. Teams often start by rewriting history because it feels like cleaning up. It is the last step, not the first.
1. Rotate first
Treat any credential that was ever committed as compromised for planning purposes. Issue a new one, update every system that uses it, then revoke the old one. Confirm the revocation actually worked by trying the old value. For a database password, that means changing it on the database, not only in the application config. For a cloud access key, it means deactivating and deleting the key, not just removing it from the file.
2. Move the new credential somewhere controlled
The replacement goes into a secrets manager or your platform's secret store, injected at runtime, with access restricted to the services and people who need it. Where possible, replace long-lived keys entirely. Short-lived credentials issued through workload identity or OIDC federation from your CI pipeline mean there is no static key to leak next time. The guide to secrets management for startups covers the options in more detail.
3. Remove it from the code
Change the code to read the secret from the environment or the secret store, and commit that change through your normal review process. This is also the point to add the secret scanner to CI and pre-commit hooks so the same mistake fails the build.
4. Decide whether to rewrite history
Once a secret is rotated, the old value in history is a dead string. Rewriting history with a tool such as git filter-repo removes it, but it forces every developer to re-clone, breaks open pull requests and does nothing about copies already made. It is worth doing when the repository will be shared outside the company, opened as source to a customer, or when the value cannot be rotated. For most internal repositories, rotation plus a recorded decision is enough. Write the decision down either way.
5. Check the logs for use
Before you close the finding, look at access logs for the systems those credentials opened, for the period they were exposed. You are looking for logins from unexpected addresses or times. If you find any, this is now an incident, and your incident response process applies.
What evidence to keep for SOC 2 and ISO 27001
A clean scan on the day of the audit is weaker evidence than a record showing you found the problem and fixed it properly. Keep:
- The scan output, dated, covering full history, and the triage list with a reason for every dismissed hit.
- For each real secret, the rotation record: when the new credential was issued and the old one revoked, and by whom.
- Screenshots or exports showing secret scanning and push protection enabled on your repositories.
- The CI configuration that runs the scanner on every pull request.
- Your secure development or cryptography policy, updated to say where secrets live and how they are rotated.
- Access log review notes for the exposure window.
Source control itself is in scope for the audit, so the same evidence set usually sits next to your GitHub access controls. The guide to securing your GitHub organization for SOC 2 covers SSO, MFA and branch protection, which keep the next secret from being reachable by the wrong people.
Why this sits at the top of a remediation plan
Secrets findings are rated high for a simple reason: they shorten every attack path. A phished developer laptop, a compromised contractor account or a misconfigured CI runner all become production access if production credentials live in the repository. They are also among the cheapest findings to close, usually days of work rather than an architectural change. In the engagement above, they led the remediation plan for both frameworks at once, alongside slower structural work such as tenant isolation.
If your audit is close and you have not scanned your history, do it before the assessor does. A finding you have already rotated and documented reads very differently from one discovered during fieldwork. A penetration test or external scan will often find the frontend variety on its own.
Common questions
Is deleting the file enough to remove a secret from git?
No. Deleting the file creates a new commit without it, but every earlier commit still contains the secret, and every existing clone keeps a copy. The only fix that makes the leak harmless is rotating the credential so the old value no longer works.
Do I have to rewrite git history before a SOC 2 audit?
Not usually. Auditors care that exposed credentials were identified, rotated and handled under your policy. Rewriting history is worth doing when a repository will be shared externally or a value cannot be rotated. Record the decision either way.
Will an auditor run a secret scanner on our code?
A SOC 2 auditor generally tests your controls rather than scanning your code, so they will ask how you detect and prevent secrets in source control and look for evidence that the control operates. A readiness assessment or penetration test is where the scanning usually happens, which is why it is better done before the audit.
How quickly should leaked secrets be rotated?
As fast as your vulnerability management policy says for the severity, and a production credential in history is normally critical or high. Set the timeline in policy, then meet it, because the auditor will test against your own stated deadline.
If you want to know what is sitting in your repositories before an assessor or buyer finds it, book a free call. We will tell you what a Phase 1 would look for and how it maps to SOC 2 and ISO 27001.
Want secrets out of your history before the audit? SOC 2 readiness starts with a fixed-price gap analysis from $3,000, ISO 27001 from $3,500, and the rest is scoped from what it finds.
See readiness pricingOr book a free call