Privacy and preparation
Coding agent secret scanning utility: remove secrets, keep tasks replayable
By SourceX Editorial · Updated
10 sections
Short answer
To remove code secrets without breaking a reproducible engineering task, rotate every credential, classify each finding by its role in the task, and give it a matching substitute: a typed placeholder, a build secret mount, recorded API responses with headers filtered, or a local stub. Then rebuild offline and replay: the same tests must fail before the fix and pass after it, with no real credentials present.
Redaction
Coding agent secret scanning
Key takeaways
- Scan agent transcripts and logs as well as code; in-session scanner findings are not a record.
- Rotate first; rewriting history hides a secret but does not make it safe.
- Choose each substitute by the secret's role: incidental, build-time, test-time, runtime or task subject.
- Remap base commits after rewriting history, or valid tasks become impossible to replay.
- A task is clean only when an offline replay matches the baseline and a second reviewer can repeat it.
How do you remove code secrets while preserving a reproducible engineering task?
Rotate every credential first, then decide what each secret does in the task and give it a substitute that keeps that job working: an inert placeholder for incidental keys, a build-time secret mount for registry tokens, recorded responses with authorization headers filtered for external API tests, and a local stub for services. Then prove it with a replay: the same tests fail before the fix and pass after it, in a fresh environment that holds no real credentials.
Deleting or masking secrets is the easy half. The harder half is showing that a cleaned engineering task still reproduces, because a coding agent dataset is only as good as its ability to rebuild the starting state, run the tests and confirm the outcome. A task that no longer builds after cleaning has lost the thing a buyer is paying attention to.
Coding agents add new places for secrets to hide
Agent sessions produce records that ordinary repositories do not: terminal output, environment dumps, tool call arguments, and issues or pull requests the agent wrote. Any of them can echo a token the agent read from a config file, so the scan for a coding agent dataset has to cover transcripts and logs, not only code.
Platform protections help during work but do not leave a record you can rely on later. GitHub's documentation says push protection blocks secrets in AI-generated responses and in actions taken through its MCP server, such as creating an issue. Its MCP secret scanning tool can be run from agent mode, but GitHub states the findings are ephemeral: they appear in the agent's chat for that session and are not stored as alerts, so they should be treated as a pre-commit check, not a system of record.
For a dataset, the scan must be repeatable and its report kept. That means running a scanner you control over the whole delivery copy, including transcripts, and keeping the report with the release.
Which secret scanning utility does which job?
Use at least two scanners with different detection methods, because each misses things the other catches. The table matches widely used tools to the job they do best in this workflow, based on each project's own documentation.
Configure scanners so their reports never repeat the secret. Gitleaks can redact secrets from its output, and every report should record the file, commit, line and secret type rather than the value. Keep the configuration files with the reports, because a broad allowlist that exempts test or fixture folders is a common reason a scan looks clean when it is not.
| Tool | What it scans | Feature that matters here | Limit to plan for |
|---|---|---|---|
| GitHub secret scanning | Entire Git history on all branches of a hosted repository | Rescans when new secret types are added | Covers hosted repositories, not transcripts or exported logs |
| GitHub MCP secret scanning tool | Code in an agent session, before commit | Catches secrets while the agent is still working | Findings are ephemeral and not stored as alerts |
| Gitleaks | Git history via git log patches, directories and files, or stdin | Baselines to separate old findings from new; redaction of output | Inline allow comments can hide findings unless ignored during audit |
| TruffleHog | Git repositories, organizations and other sources | Can report only verified results, confirmed against the provider | Verification contacts the provider, so run it only with security approval |
| Your own pattern list | Internal token formats with no public prefix | Catches company-specific secrets other tools miss | Needs maintenance as formats change |
What role does each secret play in the task?
Classify each finding by the job it does in the task before you replace it. The same API key can be noise in one repository and the heart of the test suite in another, and the right substitute depends on that role, not on the key's format.
Keep substitutes consistent. The same original value should map to the same substitute everywhere it appears, across files, commits, CI logs and agent transcripts, so that code comparing two settings, or a transcript showing the agent reading a config, still tells a coherent story after cleaning.
| Role | Example | Substitute | Replay check |
|---|---|---|---|
| Incidental | Old password in a commented-out config, unused key in a script | Typed inert placeholder that keeps the file parseable | Build and tests unchanged |
| Build-time | Private package registry token used during image build | Secret mount supplied at build time, never baked into the image | Image builds offline from a mirror; token absent from layers |
| Test-time, external API | Sandbox key used by integration tests | Recorded HTTP interactions with the authorization header filtered, replayed with no new requests allowed | Tests pass with network disabled |
| Runtime, owned service | Database or queue password for a service the team runs | Local container started for the replay with a freshly generated test credential | Service starts from the recipe; credential created at run time |
| Task subject | The bug is in key rotation or signature checking | Synthetic credential in the same format, documented as fake | Fail-to-pass tests still fail before the patch and pass after |
The source preparation and replay validation plan
The plan runs in a fixed order so each step has an input, a pass condition and a record. Steps 1 and 2 happen inside the company with valid, rotated credentials supplied through the environment; everything after step 6 must work with none.
| Step | Action | Pass condition | Record kept |
|---|---|---|---|
| 1. Freeze the task | Record base commit, problem statement, fix patch, test patch and the fail-to-pass and pass-to-pass test lists | All fields present for every task | Task record |
| 2. Baseline run | Run tests before and after the fix in the company environment | Fail-to-pass tests fail then pass; pass-to-pass tests pass | Baseline results per task |
| 3. Scan every surface | Two scanners over full history, branches, CI logs, issues, reviews and agent transcripts | Every finding triaged | Report hashes and finding locations, never values |
| 4. Rotate | Revoke or rotate each real credential found | Owner confirms rotation | Rotation ticket per finding |
| 5. Classify and substitute | Assign a role and apply the matching substitute | Every finding has a role and substitute | Substitute manifest without original values |
| 6. Rewrite history | Replace values across history and remap task anchors | Old values absent from all objects | Commit map from old to new commits |
| 7. Rebuild clean | Build from the recipe in a network-isolated container with no real credentials | Build succeeds | Build log |
| 8. Replay | Rerun step 2 on the cleaned copy | Results match the baseline for every task | Replay results and diffs from baseline |
| 9. Rescan the delivery | Scan the cleaned repository, image layers, cassettes and transcripts | No unexplained findings | Final scan reports |
| 10. Independent rerun | A second reviewer repeats steps 7 and 8 from the package alone | Same results as step 8 | Reviewer sign-off and date |
Rewriting history without breaking the task's anchors
History rewriting changes commit identities, and task records point at commits. git filter-repo's replace-text option takes a file of literal, regex or glob expressions and replaces matches with a default marker unless a replacement is given after an arrow. Choose the replacement deliberately: a bare marker in place of a quoted key can break parsing, while a typed placeholder keeps the file valid.
Every rewritten commit gets a new hash. filter-repo writes a commit map from old to new commits, and that map is how you update each task's base commit and any references in the issue text or agent transcript. SWE-bench-style task records include a base commit along with the patch, test patch and the fail-to-pass and pass-to-pass test lists, so a stale base commit silently turns a valid task into one that cannot be replayed.
Treat history rewriting as hiding, not fixing. GitHub's own guidance is to rotate an exposed credential immediately and notes that removing it from history is time-intensive and often unnecessary once it is revoked. For a licensed dataset the old value still has to go, but rotation is what makes the leak harmless.
Worked example (illustrative): a webhook retry fix that calls a sandbox API
This example is illustrative: the repository, findings and test counts are invented to show the plan in use. The task is a fix to webhook retry logic, verified by integration tests that call a third-party sandbox API.
The scan finds three secrets. A sandbox API key sits in a test fixture and is test-time; the tests are re-recorded once with valid rotated credentials, the authorization header is filtered out of the stored interactions, and replay runs with no new requests allowed. A private registry token in the CI config is build-time; it becomes a secret mount, since build arguments and environment variables persist in the final image. An old database password appears in a commit two years before the base commit and is incidental; it is replaced with a typed placeholder across history.
In this illustrative run, 2 fail-to-pass tests fail before the fix and pass after it, and 41 pass-to-pass tests pass, matching the baseline. The final scan finds one remaining match, a hash in a lockfile, which a reviewer marks as a false positive with a reason. The package ships with the commit map, the substitute manifest and both scan reports.
The exception: tasks that only work with a live credential
Some tasks cannot be replayed without a real credential, and they should be labeled that way rather than forced. Examples are tests that check a token against the issuer's live service, flows that depend on a vendor's current API behavior that recordings cannot capture, and recordings whose response bodies contain customer data that cannot be scrubbed without breaking the assertion.
Mark these tasks non-replayable and move them out of the executable set. They can sometimes remain as non-executable records of a change and its review, if their rights allow it. Never ship a live credential, even a low-privilege one, to make a task run, and never leave a recorded interaction that still carries an authorization header or session cookie.
Stop and bring in a specialist when a substitute changes behavior the task depends on, when cleaning breaks more than an occasional task, or when repository rights are unclear because of third-party or client code. Those are code ownership and security questions, not scanning questions.
Can a separate reviewer rebuild the environment from the package alone?
Yes, if the package contains everything the replay needs and nothing secret. The reviewer should receive the task records with remapped base commits, the build recipe, the recorded interactions, the substitute manifest, the commit map, the scan reports and the baseline results, and nothing else.
The reviewer builds offline, replays every task and compares results with the baseline. Any mismatch is either a substitute that changed behavior, which goes back to step 5, or a flaky test, which is recorded and excluded. Agreement between the supplier's replay and an independent rerun is the strongest evidence that cleaning did not damage the tasks.
- Recorded interactions replay with no new requests: record mode set so any unrecorded request raises an error.
- No authorization, cookie or API key fields remain in stored requests.
- Build secrets come from mounts, not build arguments or environment variables.
- Every base commit in the task records resolves in the cleaned repository.
- Scan reports list locations and types only, never original values.
Replayable, secret-free tasks in a code licensing review
Replayable tasks with a clean scan record are what make engineering history usable for coding agents. Engineering organizations can license replayable task histories through SourceX, which provides the rights review, contracting and preparation around the repositories they select. Nothing leaves before the company approves the scope and signs, very large repositories can remain in its own storage or ship on encrypted drives, and eligibility is checked through a short assessment without any code upload.
Frequently asked questions
What should a source preparation and replay validation plan include?
A frozen task record, a baseline test run, a multi-surface scan, rotation, role-based substitution, history rewriting with remapped commits, a clean offline rebuild, a replay compared with the baseline, a final rescan and an independent rerun. Each step needs a pass condition and a kept record.
Can a coding agent's built-in secret scanning replace a dataset scan?
No. In-session checks help stop leaks while the agent works, but GitHub documents that MCP scan findings are ephemeral and not stored as alerts. A dataset needs a repeatable scan over the full delivery copy, including transcripts, with the report kept.
Why not just replace every secret with the same marker?
A bare marker can break syntax and turns every secret into the same value, which changes behavior in tests that compare or parse credentials. Typed placeholders, recorded interactions and synthetic test credentials keep each secret's role intact.
Do recorded HTTP interactions leak secrets?
They can, because they store request headers and bodies. Filter authorization headers and sensitive parameters when recording, replay in a mode that forbids new requests, and scan the recordings with the rest of the delivery.
What happens to tasks that need a live credential?
Label them non-replayable and remove them from the executable set. Never ship a live credential to make a test pass; if rights allow, keep the task as a non-executable record.
Sources
- GitHub's MCP server can run secret scanning from an AI coding agent; findings are ephemeral, are not stored as alerts and should be treated as a pre-commit check. Source
- Push protection blocks secrets in AI-generated responses and in actions performed through the GitHub MCP server, such as creating an issue. Source
- GitHub secret scanning covers the entire Git history on all branches and rescans when new secret types are added; GitHub advises rotating exposed credentials immediately. Source
- Gitleaks scans git history through git log patches, directories and stdin, supports baselines and output redaction, and honors inline allow comments unless told to ignore them. Source
- TruffleHog can limit results to verified secrets. Source
- git filter-repo's replace-text option accepts literal, regex and glob expressions with a default replacement marker, and its commit map records how each commit was rewritten. Source
- SWE-bench task instances record the repository, base commit, problem statement, patch, test patch and fail-to-pass and pass-to-pass tests. Source
- Docker says build arguments and environment variables persist in the final image and recommends secret mounts for build secrets. Source
- vcrpy's filter_headers option removes or replaces headers such as authorization in recorded cassettes. Source
- vcrpy's none record mode replays recorded interactions and raises an error for any new request. Source
See if your company qualifies
A short company assessment. No data uploads are needed.