A leaked GitHub personal access token is live access to your code, and every hour it stays valid widens the investigation. This guide is the operational runbook for the first few hours: how to identify the token type, revoke it through the right channel, search the organisation audit log for everything it did, and close the side doors it may have opened. It is written for platform, security operations and incident response engineers who own GitHub organisations on GitHub.com or GitHub Enterprise Cloud. For the wider design of token policy, see the GitHub Personal Access Tokens Security Guide; this page assumes the leak has already happened.
This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.
Key takeaways
- Revoke first, investigate second. GitHub cannot restore a revoked token, but you can always issue a new one, so the cost of revoking early is a broken job, not lost evidence.
- The prefix tells you the channel.
ghp_andgithub_pat_are personal access tokens,gho_is an OAuth app token,ghu_andghr_belong to GitHub Apps, and each has a different owner who can kill it. - Search by hash, not by user. The audit log records a SHA-256
hashed_tokenfor API activity, which lets you separate what the token did from what its owner did in the browser. - Git events need a different route. Audit log searches in the web UI and REST search with
hashed_tokendo not return Git events such asgit.clone; you need the export or a stream. - Revocation does not undo persistence. SSH keys the token created keep working after an organisation revokes it, and new collaborators, deploy keys, workflows or App installations survive too.
When you need this
Run this procedure whenever a GitHub credential is seen somewhere it should not be. Typical triggers are:
- Secret scanning alert: a
secret_scanning_alert.createorsecret_scanning_alert.public_leakevent in your organisation, or a partner notification. See the Git Secret Scanning Guide. - Third-party report: a researcher, a customer or a journalist tells you a token is public. The Home Depot token exposure shows the cost of having no route for that report: the token stayed valid for more than a year and was only revoked after press contact.
- Token in logs or artefacts: a token printed in CI output, a crash report, a container image or a support ticket.
- Compromised workstation or CI runner: assume every token in that environment is exposed, including tokens stored as repository or organisation secrets.
Note that GitHub already revokes valid OAuth, GitHub App and personal access tokens pushed to a public repository or public gist on GitHub.com. That handles one channel only. A token leaked to a paste site, a public container image or a private repository a contractor can read is still live until someone acts.
Before you start
Gather these in the first ten minutes, before you change anything:
- The token value or its location. You need the raw value to compute its hash and to use the revocation API. Copy it into your incident record through a secure channel, never into chat.
- The exposure window. When was the token first exposed (commit time, image push time, log timestamp) and when was it found? Every query below is bounded by this window.
- Who owns it. The prefix narrows it down. For a fine-grained token, organisation owners can see the owner under Settings, Personal access tokens, Active tokens.
- Your access. Organisation owner rights, and for API searches a token with the
read:audit_logscope. The audit log API requires GitHub Enterprise Cloud. - What depends on it. A quick check of which pipelines or services use the token. You will revoke anyway; this list tells you what to reissue.
| Prefix | Credential type | Who can revoke it | Primary route |
|---|---|---|---|
ghp_ | Personal access token (classic) | Token owner; anyone holding the value (revocation API); enterprise owners on GHEC | Owner deletes it, or POST /credentials/revoke |
github_pat_ | Fine-grained personal access token | Token owner; organisation owners (org access only); anyone holding the value | Org Active tokens page, owner deletion, or revocation API |
gho_ | OAuth app access token | User (revoke the app authorisation); app owner; anyone holding the value | Revoke the authorisation, or revocation API |
ghu_ | GitHub App user-to-server token | User; app owner; anyone holding the value | Revocation API, then review the App |
ghr_ | GitHub App refresh token | User; app owner; anyone holding the value | Revocation API (also revoke the paired ghu_ token) |
Installation tokens and App private keys are outside this table: if those leaked, follow the How to audit GitHub Apps and OAuth apps in an organisation and regenerate the private key.
Step-by-step
Steps 1 and 2 are read-only. Steps 3 to 5 are destructive and cannot be reversed: GitHub states it cannot reactivate revoked credentials.
- Compute the token hash (read-only). On macOS or Linux, GitHub documents
echo -n TOKEN | openssl dgst -sha256 -binary | base64, replacing TOKEN with the value. GitHub also publishes a short PowerShell equivalent usingSystem.Security.Cryptography.HashAlgorithm. Record the hash in the incident ticket: from here on, the hash is how you refer to the token. - Take a quick snapshot of current activity (read-only). In the organisation audit log, search
hashed_token:"VALUE"with the quotation marks. Export the results now, so you have a baseline from before revocation. If you only have a few minutes, skip to step 3 and come back. - Revoke the token (destructive). Use the fastest route you have:
- You own the token: Settings, Developer settings, Personal access tokens, then Fine-grained tokens or Tokens (classic), and click Delete. Deleting a token that created a deploy key also deletes that deploy key.
- You are an organisation owner and it is fine-grained: organisation Settings, Personal access tokens, Active tokens, select the token and click Revoke. This removes organisation access only; the token can still read public resources and remains valid elsewhere until the owner deletes it.
- You hold the value but do not own it: send it to the credential revocation API,
POST https://api.github.com/credentials/revokewith a JSON body{"credentials": ["ghp_..."]}. The call must be unauthenticated (an authenticated call returns 403), accepts up to 1,000 tokens per request and is limited to 60 requests per hour. The owner is notified. - The owner's whole account may be compromised: the owner can use Settings, Credentials, Revoke all to remove all SSO authorisations for an enterprise; on GHEC, enterprise owners can revoke SSO authorisations or delete credentials for a user in bulk.
- Search everything the token did across the exposure window (read-only). Through the REST API, URI-escape the hash and query the organisation audit log, as GitHub's own example shows:
curl --header "Accept: application/vnd.github+json" --header "Authorization: Bearer YOUR-TOKEN" 'https://api.github.com/orgs/ORG/audit-log?phrase=hashed_token:"ESCAPED_HASH"'. Each event carrieshashed_token,programmatic_access_typeand, where applicable,token_scopes. For clones and pushes, export the audit log including Git events or query your stream, because these searches do not return them. - Remove what the attacker may have left behind (destructive). Work through the persistence table below for the window. Remove unknown collaborators, deploy keys, SSH keys, webhooks, workflow files and App installations, and restore branch protection.
- Rotate secondary secrets. If the token could read repositories, assume it read every secret committed to them and every value an attacker could exfiltrate through a workflow they pushed. Rotate those using your Secrets Rotation Runbook Template.
- Reissue access the right way. Replace the token with a fine-grained token scoped to named repositories with an expiry, or better, a GitHub App or OIDC federation for CI. Do not paste a new long-lived classic token back into the same secret.
| Audit log action | What it can mean during a leak | Response |
|---|---|---|
git.clone, repo.download_zip | Source code copied out (available through REST, export and streaming, not the web UI) | List repositories touched; review them for secrets; treat as data exposure |
git.push, workflows.created_workflow_run | Code or workflow changed, possibly to exfiltrate CI secrets | Diff and revert; rotate secrets the workflow could reach |
repo.add_member, org.add_member | New account given access, a common persistence step after a token is misused | Remove the account; check its own activity |
integration_installation.create | A GitHub App installed for durable access | Uninstall unknown Apps |
protected_branch.destroy, repo.access | Branch protection disabled or repository visibility changed | Restore settings; check for commits made while unprotected |
org_credential_authorization.grant | Credential authorised for SAML or OIDC SSO, extending reach into SSO-protected organisations | Revoke the authorisation (org_credential_authorization.revoke) |
Verify it worked
- Revocation recorded: look for
personal_access_token.access_revoked(fine-grained, organisation revoke) in the audit log, oroauth_authorization.destroyin the owner's security log. - No new events for the hash: repeat the
hashed_tokensearch an hour later and again the next day. Any event after the revocation time means you revoked the wrong token or another copy is still live. - Secret scanning alert closed with evidence: resolve the alert as revoked (
secret_scanning_alert.revoke) and link the incident ticket, rather than closing it as a false positive. - Dependants reissued: every pipeline on your dependency list runs green on its new credential.
Rollback and common errors
There is no rollback for revocation itself. What you roll back is the outage: issue a new, narrower credential to each broken job. Plan for that rather than delaying revocation.
- Revoking only at organisation level: the organisation Revoke button removes organisation access for a fine-grained token, not the token. If it is also used against other organisations or personal repositories, the owner must delete it or you must use the revocation API.
- Missing classic tokens: organisation owners cannot see or revoke classic tokens on the Active tokens page. On GHEC with SAML SSO, use the SAML authorised credentials view; otherwise use the revocation API or the owner.
- Authenticating the revocation call: an authenticated request to
/credentials/revokereturns 403. Send it without anAuthorizationheader. - Forgetting SSH keys: GitHub states SSH keys created by a revoked fine-grained token continue to work. Review the owner's SSH keys and the repositories' deploy keys.
- Hash mismatch:
echowithout-nadds a newline and produces the wrong hash. Unescaped+,/or=in a REST query silently returns nothing. - No audit log API: on GitHub Free or Team the audit log API is not available; you are limited to the web UI search, which also excludes Git events. Record that gap in the incident report.
Hardening afterwards
- Restrict classic tokens and require approval for fine-grained tokens, and set a maximum lifetime (the
personal_access_token.expiration_limit_setevent shows when it was applied). - Move CI off personal tokens to GitHub Apps or OIDC; see the GitHub Actions OIDC Federation Hardening Guide.
- Turn on push protection so the next token is blocked at commit time; see the Push Protection Guide.
- Stream the audit log with API request events and source IP disclosure enabled at enterprise level, so the next investigation includes Git events and addresses. Detection rules are in the GitHub Audit Log Detection Guide.
- Publish a disclosure route so finders can reach you without going to the press.
Measure it: time from detection to revocation (target under one hour), percentage of leaked tokens whose hash search was completed for the full exposure window, count of classic tokens with organisation access, percentage of CI jobs using App or OIDC credentials, and the number of tokens without an expiry.
| Framework | Reference | How this procedure supports it |
|---|---|---|
| MITRE ATT&CK | T1552.001 Credentials In Files; T1528 Steal Application Access Token; T1550.001 Application Access Token | The leak, the theft and the use of the token |
| NIST CSF 2.0 | RS.MI-01; RS.AN-03; PR.AA-01 | Containment by revocation, analysis by hash search, managed credentials |
| NIST SP 800-53 Rev 5 | IA-5; IR-4; AU-6; AC-6 | Authenticator management, incident handling, audit review, least privilege on reissue |
Practitioner checklist
- Identify the token type from its prefix and record the exposure window
- Compute the SHA-256 hash of the token and record it in the incident ticket
- Revoke the token through the owner, the organisation Active tokens page or the credential revocation API
- Search the audit log for
hashed_tokenacross the whole exposure window, and use the export or stream for Git events - Remove collaborators, deploy keys, SSH keys, workflows and App installations added during the window
- Rotate every secret the token could read and reissue access as a scoped fine-grained token, GitHub App or OIDC
- Confirm no new events appear for the hash after revocation
Standards and references
- GitHub Docs: REST API endpoints for revocation
- GitHub Docs: Token expiration and revocation
- GitHub Docs: Identifying audit log events performed by an access token
- GitHub Docs: Reviewing and revoking personal access tokens in your organization
- GitHub Docs: Reviewing the audit log for your organization
- GitHub Docs: Revoking your credentials
- MITRE ATT&CK: T1528 Steal Application Access Token
- NIST: Cybersecurity Framework 2.0
Related NHI Mgmt Group resources: GitHub Personal Access Tokens Security Guide · GitHub Audit Log Detection Guide · How to audit GitHub Apps and OAuth apps in an organisation · Secrets Rotation Runbook Template