1. Resources
  2. Identity Threats
  3. GitHub

GitHub Personal Access Token Theft and Abuse

Also known as: GitHub PAT theft, Stolen GitHub token, Classic PAT abuse, Fine-grained PAT abuse, ghp_ token abuse

An attacker who steals a GitHub personal access token acts as its owner over the API and Git, without a password or a second factor, until the token expires or is revoked.

Platform
GitHub
Impact
High
Last updated
Attack difficulty
Low
Detection difficulty
Medium
Privileges required: No account
No GitHub rights. The attacker needs a copy of the token, from a developer workstation, a CI system, a repository or a log.
What the attacker gains
The token owner's access to repositories and organization settings, limited by the token's scopes or permissions, with no MFA prompt.
Threat groups
APT28APT29ShinyHuntersTeamPCPAPT3APT33APT38APT5Ember BearFIN13Fox KittenHAFNIUMIndrik SpiderKe3changand 13 more in MITRE ATT&CKGroups that MITRE ATT&CK records using T1528, T1550.001, T1078.004, T1552.001.

How it works

A personal access token stands in for a user. GitHub accepts it in the Authorization header of an API request and as the password for Git over HTTPS, and treats the request as coming from the token's owner. There is no password prompt and no second factor: whoever holds the string holds the access. That makes a token a prime target for credential theft.

GitHub has two kinds, and the difference decides what a stolen one is worth.

Classic tokens (ghp_ prefix) use scopes. A classic token can reach every repository its owner can reach, in every organization the owner belongs to and in the owner's personal account. The repo scope alone gives full access to all of those public and private repositories. A scope describes a class of access; it doesn't name repositories.

Fine-grained tokens (github_pat_ prefix) are bound to a single resource owner (one user or one organization), to all or selected repositories of that owner, and to individually granted permissions. An organization can require an owner's approval before a fine-grained token can access its resources. Until approval, the token can only read public resources.

In both cases, a token can never grant more access than its owner has. Three more gates can stand between a token and an organization:

  • Organization policy. Owners can restrict or block classic tokens, block fine-grained tokens, require approval for them, and set a maximum lifetime.
  • SAML single sign-on. In an organization that uses SSO, a classic token works only after its owner authorized it for that organization.
  • Expiry and inactivity. A token with an expiry date is revoked on that date, and GitHub removes tokens that were not used for a year. A token can also be created without an expiry, unless a lifetime policy forbids it. That is long-lived secret risk in its plainest form.

Tokens leak from the places where they are used: files and commit history in repositories (see secrets leaked in GitHub repositories), the GH_TOKEN and GITHUB_TOKEN environment variables that GitHub CLI reads, the plain text file GitHub CLI falls back to when no system credential store is available, Git credential helper files, CI variables, build logs, and shell history.

Prerequisites

  • A copy of the token. No GitHub account or rights are needed beyond that.
  • The token must still be valid: not expired, not revoked, and used within the last year.
  • For organization resources: the organization's policy must allow the token class, a classic token must be SSO authorized where SSO is enforced, and a fine-grained token must have been approved where approval is required.
  • Network access to GitHub from an address the organization's IP allow list permits, if it has one.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Collect tokens

On a compromised developer workstation or build host, look in the environment and in the tools' own storage:

# Tokens passed to tools through the environment
env | grep -E '^(GH_TOKEN|GITHUB_TOKEN|GH_ENTERPRISE_TOKEN)='

# The token GitHub CLI holds for the logged-in account
gh auth token

# Where GitHub CLI keeps it (system credential store or a plain text file)
gh auth status

gh auth token prints the stored token for the current user, so a shell as the developer is enough. Source trees, CI logs and artifacts are searched with a secret scanner:

trufflehog filesystem /home/alice/src /var/lib/ci/logs

2. Classify and validate

The prefix gives the class. One request shows whether the token works, whose it is and, for a classic token, its scopes:

curl -sI -H "Authorization: Bearer $TOKEN" https://api.github.com/user
# X-OAuth-Scopes: repo, read:org, workflow

A classic token with no scopes can only read public information. Scopes worth noting: repo (all repositories), workflow (change GitHub Actions workflow files), admin:org (manage the organization, its teams and memberships), write:public_key and admin:public_key (add SSH keys to the account), delete_repo.

3. Map what it reaches

export GH_TOKEN="$TOKEN"

gh api user --jq '.login'
gh api user/orgs --jq '.[].login'

# Private repositories the token can see, and the owner's permission on each
gh api -X GET user/repos -f visibility=private --paginate \
  --jq '.[] | [.full_name, (.permissions | tostring)] | @tsv'

Setting GH_TOKEN makes GitHub CLI use the token for every command and overrides its saved credentials. GET /user/orgs returns an empty list for a fine-grained token, since it belongs to one resource owner. The rest of the map is built as in organization reconnaissance.

4. Read and write

Git over HTTPS takes the token in place of the password:

# Enter the account name and, as the password, the token when prompted
git clone https://github.com/example-org/example-repo.git

With write access the attacker pushes commits as the owner. With the workflow scope the attacker can change workflow files, which turns repository write access into code execution in the organization's CI and access to its Actions secrets.

5. Turn the token into something more durable

A token can be revoked in one click, so attackers use it to plant credentials that outlive it, where its scopes allow: an SSH key on the account or a deploy key on a repository (see SSH key and deploy key abuse), a new collaborator, or an OAuth app or GitHub App. Note that deleting a token also deletes the deploy keys that were created with it.

Impact

The attacker has the owner's reach, cut down to the token's scopes or permissions: source code, issues and pull requests, Actions configuration, and for administrative scopes the organization's membership and settings. Source code leads to more secrets, and write access to a build repository leads to the software the organization ships.

The access lasts as long as the token. A classic token created without an expiry and used regularly never ages out, and nothing ties it to the laptop it was created on.

OPSEC and artifacts

  • No sign-in event. Token use is not an interactive sign-in. There is no password or MFA event to alert on. What remains is the audit record of each action, which carries the token's hash and programmatic_access_type.
  • Reading instead of changing. Read-only API calls are not in the ordinary organization audit log. They appear only as api.request events when the enterprise streams API requests. Clones appear as git.clone Git events, which are kept for seven days and are not shown in the web interface.
  • Blending in. Using the token from the owner's usual network, with the user agent of Git or GitHub CLI and at a developer's pace, looks like the developer. A new address, a scripted user agent or a burst of clones is what stands out.
  • Staying inside what is already approved. A stolen token that is already SSO authorized and already approved writes no new org_credential_authorization.grant or personal_access_token.access_granted event. Creating a new token as the user does.
  • Last used time. Token metadata shows when a token was last used, not what it did or which repository it touched. An owner who checks their token list after a theft sees a recent use and nothing else.
  • A rejected request is still a trace. A request denied by policy can show that the token was presented, even though no resource was accessed.

Detection

  • Follow the token by its hash. Compute the hash and search the audit log. This covers personal access tokens, OAuth tokens and GitHub App tokens.
echo -n "$TOKEN" | openssl dgst -sha256 -binary | base64
hashed_token:"VALUE"

Without the token value, export the enterprise credential inventory and take hashed_token from it. Git events are not returned by the audit log search; export or stream them.

Inventory is the other half. Organization owners can list the credentials members authorized for SSO, including classic tokens, with their scopes and last access time:

gh api orgs/example-org/credential-authorizations --paginate \
  --jq '.[] | [.login, .credential_type, .token_last_eight, (.scopes | join(",")), .credential_authorized_at, .credential_accessed_at] | @tsv'

Fine-grained tokens with access to the organization are listed by GET /orgs/{org}/personal-access-tokens, which only a GitHub App can call.

Mitigation

  • Revoke on suspicion. The owner deletes the token, or an organization owner removes its SSO authorization (DELETE /orgs/{org}/credential-authorizations/{credential_id}) or revokes a fine-grained token's access. GitHub also accepts tokens reported by third parties for revocation. Then review what the token did. See secret rotation.
  • Restrict classic tokens in the organization's personal access token policy, and require approval for fine-grained tokens, so every token that reaches the organization names its repositories and permissions. This is least privilege applied to tokens.
  • Set a maximum token lifetime so that no token is created without an expiry.
  • Enforce SAML single sign-on so that classic tokens need explicit authorization and an owner can withdraw it centrally. With Enterprise Managed Users, owners can also delete a user's credentials.
  • Add an IP allow list so a token is useless from outside the corporate network or the CI runners.
  • Replace tokens in automation. Use the built-in GITHUB_TOKEN in GitHub Actions and GitHub App installation tokens, which expire after one hour, in place of a person's token in a pipeline.
  • Keep tokens out of files. Store them in a credential manager, enable secret scanning and push protection, and treat a token like a password.
  • Offboard by credential, not only by account. When someone leaves or changes role, remove organization membership and outside collaborator grants, and check the SSO credential list for what they authorized.

The personal access token security guide walks through the organization policy, a least-privilege token template and an inventory script.

Detection rules for this attack

Log events to collect

FAQ

Does two-factor authentication protect against a stolen personal access token?

No. A personal access token is a complete credential for the API and for Git over HTTPS. GitHub doesn't ask for a password or a second factor when it is presented. The controls that still apply are the token's own scopes or permissions, its expiry, the organization's token policy, SAML single sign-on authorization for classic tokens, and an IP allow list.

What is the difference between a classic and a fine-grained token for an attacker?

A classic token reaches every repository and organization its owner can reach, limited only by coarse scopes such as repo. A fine-grained token is bound to one resource owner, to all or selected repositories, and to individual permissions, and an organization can require an owner's approval before it works. A stolen classic token is usually worth much more.

Does a token stop working when its owner leaves the company?

Only if the departure removes the access behind it. A token never grants more than its owner has, so removing the account from the organization cuts the token off from organization resources. If the account stays a member or outside collaborator, or the person used a personal account that the company can't delete, the token keeps working until it expires or someone revokes it.

How do you find what a stolen token did?

Compute the SHA-256 hash of the token, Base64 encoded, and search the audit log for hashed_token with that value. The log also records the type of credential in programmatic_access_type. Git events such as clones are only in exports, the API and the stream, and are kept for seven days.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.