Join our Newsletter — 33% off our NHI Course
Home› Guides› How to revoke a leaked GitHub personal access…
Guide Non-Human Identity (NHI)

How to revoke a leaked GitHub personal access token and check what it touched: Kill the token, then trace every action

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 12 min read
On this page

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_ and github_pat_ are personal access tokens, gho_ is an OAuth app token, ghu_ and ghr_ 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_token for 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_token do not return Git events such as git.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.create or secret_scanning_alert.public_leak event 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:

  1. 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.
  2. 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.
  3. 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.
  4. Your access. Organisation owner rights, and for API searches a token with the read:audit_log scope. The audit log API requires GitHub Enterprise Cloud.
  5. 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.
PrefixCredential typeWho can revoke itPrimary route
ghp_Personal access token (classic)Token owner; anyone holding the value (revocation API); enterprise owners on GHECOwner deletes it, or POST /credentials/revoke
github_pat_Fine-grained personal access tokenToken owner; organisation owners (org access only); anyone holding the valueOrg Active tokens page, owner deletion, or revocation API
gho_OAuth app access tokenUser (revoke the app authorisation); app owner; anyone holding the valueRevoke the authorisation, or revocation API
ghu_GitHub App user-to-server tokenUser; app owner; anyone holding the valueRevocation API, then review the App
ghr_GitHub App refresh tokenUser; app owner; anyone holding the valueRevocation 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.

  1. 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 using System.Security.Cryptography.HashAlgorithm. Record the hash in the incident ticket: from here on, the hash is how you refer to the token.
  2. 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.
  3. 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/revoke with 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.
  4. 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 carries hashed_token, programmatic_access_type and, 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.
  5. 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.
  6. 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.
  7. 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 actionWhat it can mean during a leakResponse
git.clone, repo.download_zipSource 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_runCode or workflow changed, possibly to exfiltrate CI secretsDiff and revert; rotate secrets the workflow could reach
repo.add_member, org.add_memberNew account given access, a common persistence step after a token is misusedRemove the account; check its own activity
integration_installation.createA GitHub App installed for durable accessUninstall unknown Apps
protected_branch.destroy, repo.accessBranch protection disabled or repository visibility changedRestore settings; check for commits made while unprotected
org_credential_authorization.grantCredential authorised for SAML or OIDC SSO, extending reach into SSO-protected organisationsRevoke 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, or oauth_authorization.destroy in the owner's security log.
  • No new events for the hash: repeat the hashed_token search 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/revoke returns 403. Send it without an Authorization header.
  • 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: echo without -n adds 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_set event 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.

FrameworkReferenceHow this procedure supports it
MITRE ATT&CKT1552.001 Credentials In Files; T1528 Steal Application Access Token; T1550.001 Application Access TokenThe leak, the theft and the use of the token
NIST CSF 2.0RS.MI-01; RS.AN-03; PR.AA-01Containment by revocation, analysis by hash search, managed credentials
NIST SP 800-53 Rev 5IA-5; IR-4; AU-6; AC-6Authenticator 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_token across 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

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

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.