Skip to main content

GitHub Personal Access Token

A GitHub Personal Access Token (PAT) is a credential used to authenticate to GitHub services, allowing users to perform actions on behalf of a GitHub account. This token can be used for accessing repositories, managing issues, and automating workflows. Exposure of a PAT is a significant security concern because it can grant unauthorized access to sensitive repositories, potentially leading to data breaches or unauthorized code changes.


How Does It Look

Personal Access Tokens can appear in various contexts, such as:

  • Environment variables:

    export GITHUB_TOKEN=ghp_XXXXXXXXXXXXXXXXXXXXXX
  • Configuration files (JSON, YAML, .env):

    {
    "github": {
    "token": "ghp_XXXXXXXXXXXXXXXXXXXXXX"
    }
    }
  • Code snippets:

    import requests

    headers = {"Authorization": "token ghp_XXXXXXXXXXXXXXXXXXXXXX"}
    response = requests.get("https://api.github.com/user", headers=headers)
  • Connection strings (if applicable): Not typically used in connection strings.


Severity

  • 🔴 Critical

The severity of a GitHub Personal Access Token exposure is critical because it can provide full access to the repositories associated with the token's permissions. This includes the ability to read, modify, or delete code, which can have a significant impact on the integrity and security of the software. The blast radius can extend to all repositories the token has access to, potentially affecting multiple projects and teams.


What Can an Attacker Do?

With immediate access to a compromised GitHub Personal Access Token, an attacker can perform a variety of malicious actions:

An attacker can immediately access repositories and perform actions based on the token's permissions.

Key actions an attacker can perform:

  • Read or modify code: Access source code and make unauthorized changes (if the token has write permissions).
  • Delete repositories: Remove entire repositories, leading to data loss (if the token has admin permissions).
  • Access sensitive data: Extract confidential information stored in repositories (if the token has read access).
  • Trigger CI/CD pipelines: Initiate builds or deployments, potentially injecting malicious code (if the token is used in CI/CD processes).

Additionally, an attacker could escalate their access by using the token to explore other connected services or repositories, potentially leading to further compromise of the organization's infrastructure.


Real-World Impact

The exposure of a GitHub Personal Access Token poses significant business risks, including:

The primary impact is the unauthorized access to and manipulation of source code.

Potential consequences include:

  • Data Exposure: Source code and sensitive data within repositories (if the token has read access to private repositories).
  • Financial Loss: Costs associated with data breaches, incident response, and potential downtime (if repositories are deleted or modified).
  • Operational Disruption: Interruption of development workflows and CI/CD processes (if the attacker modifies or deletes critical code).
  • Reputational Damage: Loss of trust from customers and partners due to compromised code integrity.

In a worst-case scenario, the exposure could lead to a cascading effect where compromised code is deployed to production, affecting end-users and potentially leading to widespread security incidents.


Prerequisites for Exploitation

To exploit a GitHub Personal Access Token, an attacker needs:

  • Network access: Ability to connect to GitHub services.
  • Additional context: Knowledge of the associated GitHub account and repositories.
  • No rate limits: Exploitation is easier if the token is not subject to strict rate limits or IP restrictions.

How to Verify If It's Active

To verify if a GitHub Personal Access Token is active, use the following command:

curl -H "Authorization: token [TOKEN]" https://api.github.com/user

Valid credential response: A successful response will return user information, such as the username and associated email.

Invalid/expired credential response: An error message indicating unauthorized access or invalid credentials.


Detection Patterns

Common Variable Names:

  • GITHUB_TOKEN
  • GH_TOKEN
  • PERSONAL_ACCESS_TOKEN
  • GITHUB_PAT
  • TOKEN
  • ACCESS_TOKEN

File Locations:

  • .env
  • config.json
  • settings.yaml
  • credentials.txt
  • secrets.json

Regex Pattern:

ghp_[A-Za-z0-9_]{36}

Remediation Steps

  1. Revoke immediately - Go to GitHub > Settings > Developer settings > Personal access tokens and delete the compromised token.
  2. Audit access logs - Review GitHub audit logs for unauthorized access or actions performed with the token during the exposure window.
  3. Assess blast radius - Identify all repositories and services that used the exposed token.
  4. Rotate credential - Generate a new Personal Access Token with the necessary permissions and update all dependent systems.
  5. Update dependent systems - Deploy the new token to all applications and update CI/CD pipelines securely.
  6. Harden access controls - Enable IP allowlisting and enforce two-factor authentication for GitHub accounts.
  7. Implement secrets management - Migrate tokens to a secrets manager (HashiCorp Vault, AWS Secrets Manager) to prevent hardcoding.
  8. Add detection controls - Set up pre-commit hooks and repository scanning to catch token leaks before they reach production.

Credential exposures often go undetected for extended periods, increasing the window for exploitation. As a long-term strategy, plan to establish an internal process or engage an external vendor for continuous external exposure monitoring. This helps identify leaked secrets across public repositories, paste sites, dark web forums, and other external sources before attackers can leverage them. Proactive detection and rapid response are essential to minimizing the impact of credential leaks.


References