Privacy and preparation
How to scan code repositories for secrets before sharing them
By SourceX Editorial · Updated
Short answer
To scan a repository for secrets before sharing it, mirror-clone every repository with all branches and tags, run at least one scanner over the full commit history, triage each finding as live, revoked, test or false positive, rotate anything live, then rescan the exact copy you will share. A clean main branch proves nothing about history.
Key takeaways
- Secrets removed from current code still exist in old commits, branches and tags until history is rewritten or left out.
- Mirror clones capture every ref; ordinary clones can miss branches and tags that a recipient would receive.
- Two scanners with different detection methods can catch secrets that one tool misses; compare their results rather than trusting either alone.
- Every finding needs a triage label and an owner, and live credentials are rotated at the source.
- The final scan runs on the exact copy being shared, and its report goes into the release record.
What does a pre-sharing secrets scan need to cover?#
A pre-sharing secrets scan needs to cover everything a recipient could read: every repository in scope, every branch and tag, the full commit history and the non-code files that travel with the code. Scanning only the default branch tells you what is in the code today, not what a reader of the history will find.
Build the scope list before choosing tools. Most missed secrets come from repositories nobody remembered, not from weak detection rules.
- Active, archived and forked repositories, including those inherited from acquired products.
- All branches and tags kept on the server, not only main.
- Configuration and infrastructure files: environment files, CI pipelines, Terraform state and Helm values.
- Notebooks, test fixtures, seed data and sample configuration files.
- Large files tracked outside normal git storage, if they are in scope.
- Wiki repositories and issue attachments, if they will be shared alongside the code.
Gitleaks, TruffleHog and platform scanning compared#
Gitleaks and TruffleHog are the two most common open-source choices, and they suit different jobs. Platform scanning, such as the secret scanning built into GitHub, is useful for ongoing protection, but its coverage depends on your plan and settings, so check the documentation before relying on it for a one-time release.
A practical setup runs gitleaks for broad pattern coverage and TruffleHog with verification for triage, then compares the two result sets. Check the license terms if you plan to embed either tool in your own product rather than run it internally.
Whichever tools you choose, pin their versions for the release scan. Rule sets change between versions, and a rerun with a newer version can produce different findings, which is useful later but confusing in the middle of triage.
| Tool | License | Strength | Watch for |
|---|---|---|---|
| Gitleaks | MIT | Fast rule-based scanning of git history, files and stdin; 222 default rules as of July 2026 | Declared feature complete in May 2026; future releases are security patches only |
| TruffleHog | AGPL-3.0 | Classifies over 800 secret types, can check whether a secret is live, and also scans chats, wikis, logs and object stores | Live verification sends real authentication requests |
| Platform secret scanning | Part of the code host | Continuous alerts and push protection where available | Coverage varies by plan, repository visibility and settings |
Step by step: scanning before a release#
Scanning before a release takes eight steps, from a list of repositories to a scanned, shareable copy. Steps 1 and 2 are where most gaps begin, so give them the most attention.
Keep the scan configuration, tool versions and the commit hash of each mirror with the results. If a question comes up later, you can show exactly what was scanned and rerun it.
- Step 1: inventory every repository in scope from the code host's admin view, including archived ones, and record an owner for each.
- Step 2: create mirror clones so every branch, tag and ref is present locally, including pull request refs on hosts that expose them, since those can hold commits never merged into main.
- Step 3: run each scanner over the full history of each mirror, confirm in its options that it walks every branch and tag rather than only the checked-out one, and save results in a machine-readable format.
- Step 4: add custom rules for internal token formats, such as your own service keys or license keys, and rerun.
- Step 5: de-duplicate findings across tools and commits so one secret becomes one triage item.
- Step 6: triage each finding and assign an owner.
- Step 7: rotate live credentials at the source, then decide whether to rewrite history or ship a fresh snapshot.
- Step 8: rescan the exact copy you will share and keep the report.
How to triage findings#
Triage turns a long scanner report into decisions. Every finding gets one label, an owner and an action, and nothing is closed without a written reason.
Allow list specific matches by fingerprint rather than disabling a rule, so the same pattern elsewhere is still caught on the next run.
| Label | Example | Action |
|---|---|---|
| Live | A cloud access key that still authenticates | Rotate now, review access logs, then remove |
| Revoked or expired | An old webhook URL for a deleted workspace | Confirm revocation; remove from the shared copy |
| Test or dummy | A placeholder key in a unit test | Confirm it was never real; allow list with a note |
| False positive | A random-looking hash or encoded asset | Allow list the specific match, not the rule |
| Customer or third-party secret | A customer's API token pasted into a fixture | Have the owner rotate it; follow your incident process and contract notice terms |
Verification and other operational cautions#
Live verification of secrets needs operational care because it uses the credentials it finds. TruffleHog's live check confirms a secret by attempting to authenticate with it, which means your scan contacts third-party services using credentials that may belong to customers or vendors. Agree internally on when verification runs, from which network and who reviews the results.
Scanner output is itself sensitive: a report lists every secret found, often in plain text. Store reports with restricted access, never attach them to the dataset, and delete working copies once triage is closed.
Plan for tool change as well. The gitleaks README stated in May 2026 that the project is feature complete and that the maintainer's focus is shifting to a separate project, Betterleaks, so new secret formats may not reach its default rules.
Illustrative: a freight software vendor scans before a code license#
Illustrative: a fictional transportation management software vendor prepares its code and code review history for a licensing review. It runs self-managed GitLab, with a monorepo, several archived services and a repository inherited from an acquired routing product.
The first scan of the main branch is clean. The full-history scan of mirror clones finds a cloud access key in an old Terraform state file, a chat webhook in a notebook, test keys in fixtures and a customer's EDI credentials in an archived integration test. The cloud key and the customer credentials are still live.
The CTO rotates both, notifies the customer under its agreement, excludes the acquired product's repository pending a rights review and builds a fresh snapshot of the remaining repositories. The final scan of that snapshot is clean, and the report goes into the release file.
How SourceX approaches code and credentials#
SourceX handles code in the Preparation step of the SourceX five-step transaction, after the Rights step has excluded customer-owned code and third-party material the company cannot license. A secrets scan is part of preparing any code package.
The privacy record and release authorization in the SourceX Evidence Packet note that scans covered full history, which tools were used and that the final scan ran on the delivered copy. The supplier approves the release.
Frequently asked questions
Is a clean scan of the main branch enough?
No. Secrets deleted from current files remain in earlier commits, other branches and tags, and anyone who receives the full history can find them. Either scan and clean the full history, or share a fresh snapshot without history and scan that.
Should we rewrite git history or share a snapshot?
A fresh snapshot without history is simpler and safer when history is not needed. When commit history and code reviews are part of what is licensed, rewrite history on a copy after rotating every live secret, then rescan. Never rewrite the working repository your team uses.
Is gitleaks still safe to use?
Yes for now, with a caveat. Its existing rules still work and it still receives security patches, but new secret formats may not be added. Pair it with a second scanner and add custom rules for your own token formats.
What about secrets in Jira, Confluence or Slack?
Code is only one place credentials leak. Tickets, wiki pages and chat threads often hold pasted keys, connection strings and passwords. If those systems are part of the package, scan their exports too; some scanners support chat and wiki sources directly.
Who should own the scan?
An engineering lead who knows the systems should run it, with security reviewing triage decisions. The CTO or another authorized person signs off that every live secret was rotated and that the final scan covered the delivered copy.
Should we scan vendored code and dependencies too?
Yes, if they sit in the repository you will share. Vendored libraries, copied SDKs and bundled sample projects can contain test or real keys from their authors. They also raise license questions, since third-party code may not be yours to license, so flag them for the rights review as well.
Sources
- Gitleaks is an MIT-licensed tool for detecting secrets such as passwords, API keys and tokens in git repositories, files and stdin; as of July 2026 its default configuration contains 222 detection rules. Source
- On May 21, 2026, the gitleaks README was updated to state that Gitleaks is feature complete, future releases will be security patches only, and the maintainer is shifting focus to Betterleaks. Source
- TruffleHog is an AGPL-3.0 secret scanner that says it classifies over 800 secret types, can log in to confirm whether a secret is live, and scans Git, chats, wikis, logs, object stores and filesystems. Source
Related resources
See if your company qualifies
A short company assessment. No data uploads are needed.