The First-Hour Response and Follow-Up Runbook for an Exposed Credential

You have just noticed an API key in your Git history. Perhaps you committed a .env file, pasted a test credential into a script, or added a screenshot containing a dashboard value. The immediate temptation is to delete the offending commit and push the change. That may remove the value from the latest version of the repository, but it does not invalidate the credential or remove it from earlier commits, clones, forks, caches, or logs.

Treat this as an incident response problem rather than a Git cleanup problem. For a founder, the priority is to prevent the exposed credential from being used against your infrastructure, accounts, data, customers, or operating costs. This runbook covers the first-hour sequence and the follow-up work: revoke and replace the credential, preserve evidence, classify and audit the exposure, search the repository, decide whether history rewriting is justified, and improve controls so the next mistake is easier to contain.

1. Revoke, replace, and restore production access

Open the provider’s dashboard and disable or delete the credential that was exposed. Do this before editing the repository or discussing the incident. Revocation makes the old credential unusable; it is the immediate action that reduces active risk.

Replacement is a separate, necessary step. Issue a new credential with the required permissions, update every consumer, and verify that the new credential works. Rotation is the broader process: revoke the old value, create or receive a replacement, update consumers, and confirm that the replacement works while the old credential still fails.

Only create the replacement after the old credential has been revoked. Then update the systems or environment variables that use it, test the replacement, and confirm that the old one fails. This replacement and consumer-update work belongs in the first-hour sequence because deleting a commit does not restore production functionality. If a service cannot safely continue without the credential, document the outage risk and use the provider’s documented recovery path rather than delaying revocation.

Do not assume the value belongs only to the service whose name appears in the filename or commit. Developers often reuse the same value in multiple files, branches, scripts, local environments, and deployment configuration. Search the affected projects for the specific credential and review each service’s access logs, usage records, and security events.

2. Preserve evidence before making destructive changes

Before rewriting history, record what you can about the incident:

  • The repository, branch, commit, and approximate time of exposure.
  • Whether the repository was public or private and who could access it.
  • The type, permissions, restrictions, and last known use of the credential.
  • Provider logs showing activity before and after revocation.
  • Any unusual requests, billing changes, data access, infrastructure changes, or other relevant events.
  • Which credential consumers were updated and when.

Preserve relevant provider audit logs, repository metadata, and deployment records according to your organization’s retention policy. Do not paste the live secret into tickets, chat messages, screenshots, or the incident document. Record a redacted identifier or a secure reference instead.

If the provider offers a way to review API activity, inspect it immediately. Look for unfamiliar sources, unusual request volumes, changes outside normal operating hours, actions your product does not perform, and access from accounts or locations you do not recognize. If the provider cannot determine whether the credential was misused, document that limitation rather than declaring the incident harmless.

3. Classify the exposure conservatively

Not every exposed value has the same authority. Some values are intentionally included in client-side code, such as a publishable client identifier or an analytics token. Their impact still depends on how the provider configures them, what actions they permit, and what restrictions are applied. Exposure alone does not establish severity, and it does not prove that the worst possible outcome is limited to billing or rate limiting.

Other credentials can permit privileged operations. Examples include cloud access keys, live payment keys, database connection strings, OAuth client secrets, and tokens that grant write access, billing authority, or direct access to customer data. These require prompt revocation and a closer review of provider activity.

If you cannot determine whether a value is public-facing or privileged, treat it as privileged until the provider’s documentation and configuration show otherwise. Check the credential’s documented permissions, applicable restrictions, and recent use. Avoid relying on naming conventions alone: a variable name such as NEXT_PUBLIC_ or VITE_ is not proof that a value is safe to expose.

The classification should state what is known, what is unknown, and what evidence would resolve each important uncertainty. It should not turn a missing log into proof that no misuse occurred.

4. Search the working tree and relevant Git history safely

A deletion in the latest commit only proves that the value is absent from that version. It may remain in an earlier commit, another branch, a tag, a merge result, or a file that was added and removed during development.

Run a local search that does not print the secret value. First, determine the repository root and confirm that you are working with the correct checkout:

git rev-parse --show-toplevel
git status --short

Search tracked and untracked working-tree files while redacting matches. This example searches the current directory and skips common binary files, local Git metadata, and dependency directories:

grep -RIl --exclude-dir=.git --exclude-dir=node_modules --exclude-dir=vendor --exclude='*.png' --exclude='*.jpg' --exclude='*.jpeg' --exclude='*.gif' --exclude='*.zip' 'EXACT_SECRET_VALUE' .

Replace EXACT_SECRET_VALUE with the actual value locally. The -l option lists filenames only, so it does not print matching lines. Review the named files securely and remove the credential from them. If the value is no longer known, search for distinctive prefixes or suffixes instead, taking care that the pattern does not reveal the complete credential.

Do not rely on this working-tree search alone. It will not find the value in commits that are no longer present in the checked-out files. To search Git history without displaying the live value, use Git’s object plumbing and filter the output to object names and matching paths.

One option is to iterate through commits on all local refs and inspect each commit’s tree for a filename pattern associated with the incident:

git rev-list --all --objects | grep -Ei '(^|/)([^/]*(secret|credential|key|token|env)[^/]*)$'

This narrows the review to potentially relevant paths, but it is not a complete secret scanner. For an exact-value check that does not print the value, create a temporary file containing the credential, set restrictive permissions, and use git grep against each commit with the output restricted to file names:

printf '%s' 'EXACT_SECRET_VALUE' > .incident-secret-search
chmod 600 .incident-secret-search
git rev-list --all | while read commit; do
  git grep -Il -F -f .incident-secret-search "$commit" -- 2>/dev/null || true
done
rm -f .incident-secret-search

The git grep -l form reports matching paths without printing the matching lines. The loop can be slow on large histories because it inspects every commit, so use it only when the repository size and incident urgency justify the wait. The temporary file contains the live value and creates local risk: keep it out of version control, restrict its permissions, and delete it promptly. An approved secret-scanning tool or service that redacts values is preferred where available.

Also inspect branches, tags, remotes, and relevant pull-request or fork locations. Local git rev-list --all covers refs available in the local repository, but it does not include every copy that may exist on a remote or in a fork. A complete search therefore requires checking remote hosting and collaboration locations under your organization’s access controls.

5. Audit provider activity and handle suspected misuse

There are two questions to answer: what happened, and what should happen next?

If provider logs show no suspicious use during the available retention window, record that as a bounded finding: the reviewed period showed no identified misuse. Do not turn it into a claim that the credential was never used. If logs are missing, incomplete, or unavailable, state the gap.

Contact the provider’s security or support channel when you need help determining whether a credential was used, whether a suspicious event can be attributed to it, whether a key can be restricted further, or whether related credentials should be rotated. Provide a redacted incident reference rather than sending the live secret through an unapproved channel.

Escalate suspected unauthorized use to the provider immediately. Preserve the relevant request IDs, timestamps, source information, account identifiers, and affected resources. Follow the provider’s process for disputing unauthorized charges or requesting an investigation, but do not assume a dispute will reverse billing automatically.

Notify affected parties when the facts support a material exposure or when applicable contractual, regulatory, or customer-communication obligations require it. The notice should explain what information may have been exposed, what protective action you took, what users should do, and where they can obtain support. Avoid speculation and unnecessary technical details that could increase risk.

If customer data may have been accessed, scope the systems and data involved, involve the appropriate security, legal, and compliance owners, and follow your incident-response and notification procedures. If the provider or your investigation confirms unauthorized use of a privileged credential, expand the response to resources the credential could reach rather than limiting the review to the original commit.

For a solo founder, these steps may feel disproportionate. The goal is not certainty before acting. Revoke quickly, preserve what evidence exists, replace the credential and restore legitimate operations, learn what the provider can confirm, and communicate responsibly when the potential impact reaches customers or contractual obligations.

6. Decide whether to rewrite history

History rewriting can reduce future exposure, but it does not revoke a credential, remove prior copies, or prove that no one used the value. It also changes commit identifiers and can disrupt every clone, fork, open branch, and pull request based on the old history.

For a private repository with limited access and a credential that has already been revoked, the remaining Git history may present less operational risk than the disruption caused by a coordinated rewrite. That decision still depends on who had access, whether the repository was shared, and whether the credential appeared in logs, artifacts, or backups.

For a public repository, rewriting history is generally useful because it removes the value from the rewritten branch. However, old commits may remain accessible through forks, pull requests, caches, archives, or prior clones. A rewrite is risk reduction, not a guarantee of deletion.

If you rewrite history, plan the operation before changing it:

  1. Confirm that the credential has been revoked and the replacement is working.
  2. Coordinate with collaborators because commit identifiers will change.
  3. Choose an appropriate history-rewriting method and test it on a disposable clone.
  4. Rewrite all affected branches and tags, not only the default branch.
  5. Force-push according to the hosting provider’s procedures, with the required coordination and safeguards.
  6. Ask collaborators to reclone and rebase open work rather than continuing from old clones.
  7. Verify that the value is absent from the rewritten refs and that the new credential works in deployed systems.
  8. Keep monitoring provider activity after the cleanup.

Do not perform a rushed rewrite while a live credential remains usable. Revocation addresses active risk; history cleanup addresses future repository contents. For many teams, the practical founder decision is to preserve evidence, complete the replacement, search the relevant locations, and treat rewriting as a coordinated change with an owner rather than an improvised first response.

7. Prevent the next exposure

Incident response is not finished until the workflow makes the same mistake harder to repeat.

  • Secret management: Store credentials in an appropriate secrets manager or deployment platform’s secret store. Keep local environment files out of version control, and never use them as a substitute for production secret management.
  • Pre-commit checks: Scan staged changes for secrets before commit. Hooks can be bypassed, so treat them as one layer rather than the only control.
  • Server-side push protection: Use hosting controls that can reject detected secrets before publication. Verify how they handle the branches and automation paths used by your team.
  • Secret scanning: Configure repository or platform scanning for working trees and history, with alerts routed to an owner who will act on them. Test that redaction prevents the tool or alert from copying the live value into another system.
  • Least privilege: Give each credential only the permissions and scope it needs. Restrict source addresses where the provider supports it, and separate development, test, and production credentials.
  • Short-lived credentials where supported: Prefer temporary credentials for workloads that can use them, reducing the useful life of a leaked value.
  • Deployment review: Check build artifacts, logs, screenshots, support bundles, and generated files before they enter a repository or are shared outside it.
  • Ownership and response: Assign someone to receive alerts, revoke credentials, inspect logs, and update dependent systems. A detection mechanism without an owner still creates delay.

Treat every committed value as potentially recoverable from history. If a credential enters a commit, revoke it; do not assume that a later deletion or history rewrite is enough.

The safe operating sequence is therefore: revoke the exposed credential, replace it and update consumers to restore legitimate operations, preserve evidence, classify and audit the exposure, search the working tree and history, then decide whether rewriting history is worth the disruption. This order protects customers, revenue, and operating continuity before optimizing the appearance of a clean commit graph.

Sources