Get the free coreGet core

GitHub account hacked: what to do now, in order

Updated 7 min readSection 05 / Threats
SHORT ANSWER

If your GitHub account is hacked, do these in one order. First check the Mac for a background program that reacts when a token is revoked, and stop it before any revocation. Then, from a clean device, revoke your sessions, tokens, SSH keys and authorized apps in GitHub settings and create narrower tokens. Then turn on two-factor authentication. Then rotate the secrets those tokens reached, and last look through your repositories for commits you did not make.

A GitHub account hacked from a developer's Mac does not need a guessed password. A stolen token or browser session is enough, because stolen tokens and cookies can be used to impersonate you. The steps below follow that logic: find the cause, cut the access, rotate what it reached, then look for damage.

011. Check the Mac first

Do this before you revoke anything, for one reason. On developer Macs infected by the Mini Shai-Hulud npm malware, a background program polls GitHub every 60 seconds, and when it gets an error because its token was revoked, it tries to run rm -rf ~/, a command that deletes your home folder. It is installed through a macOS LaunchAgent, a small config file that makes macOS start a program on its own.

So look first, and start with one file: ~/Library/LaunchAgents/com.user.gh-token-monitor.plist. If it is there, don't revoke any GitHub token yet, from this Mac or any other device, because the program fires when the token it checks is revoked. Stop it first, since macOS loads and unloads background agents with the launchctl command, or wait until it exits by itself after 24 hours without firing. The Shai-Hulud page has the details. Then open Login Items & Extensions settings, which lists the items that open automatically whenever you log in, and look for LaunchAgents and LaunchDaemons you do not recognize. If you find something, clean the Mac before you touch the tokens; how to check for an infostealer walks through it. If you find nothing, that is not proof the Mac is clean, because a stolen session lets attackers act without persistence on the original machine. Browser sessions, which a stealer can copy along with passwords, are covered on cookie hijacking.

022. Revoke tokens and keys from a clean device

Use a phone or laptop you trust that never touched the suspect Mac, or use the Mac only after it is clean. A new token typed into an infected Mac can be stolen again, since a stealer takes browser data and session tokens.

On a personal account you revoke access piece by piece. Every path starts at your profile picture in the upper-right corner, then Settings:

GitHub also offers revoking all your credentials at once from account settings, for the case where your account may be compromised or your hardware was lost or stolen. What that page offers depends on the account type: revoking SSO authorizations in an enterprise, and deleting all keys and tokens only for members of an enterprise with managed users.

A revoked or expired token cannot be restored, so you or the application must create a new one. When you do, make the new ones narrower:

033. Turn on two-factor authentication

Enable multi-factor authentication (MFA, a second proof at login such as a code on your phone) for your important accounts, and change the passwords that were stored on the affected Mac, after it is clean. Do this in your account's security settings, from the clean device. MFA protects the login moment. A session that is already stolen is why the first two steps matter more.

044. Rotate what the tokens could reach

Your account is a key to other things. Rotating means replacing a secret with a new one and revoking the old one. For a leaked secret, revoking or rotating it is the first step, and that may be enough without rewriting Git history. The most important step is revoking the secret with its provider, not deleting it from your code; that usually means logging into the provider's portal and finding where the secret is managed.

Do this for each secret in your repositories, Actions workflows or on the Mac: cloud keys, package registry tokens, API keys. The cloud-key order is on leaked API keys, and removing a secret from Git history is on remove secrets from Git history. If you worry about downtime for a service, you can generate a new secret first, switch the application to it, then revoke the old one. Check the provider's logs for use of the secret; for AWS keys, review CloudTrail Event history for unsanctioned creation of access keys, policies, roles or temporary credentials.

The second tier is where attacks continue. In the ultralytics case, the second round of malicious releases came from an unrevoked PyPI API token still available to the GitHub Actions workflow.

055. Look for code pushed under your name

This step comes last because it is a read-only check: nothing here changes your account, and by now the old tokens no longer work.

An attacker with your token can write to your repositories. Look for what was added.

What to look atWhy
Commits you do not recognizeAn inappropriately scoped GitHub token let a threat actor commit malicious code that shipped in a release
.vscode/tasks.json in your reposMalicious tasks.json files were injected into 400+ GitHub repositories, and a task with runOn folderOpen runs when the folder opens
Pushes to branches your agent can reachIn auto mode Claude Code may push to any branch of the repo it works in
Package publishing tokensA token left unrevoked in a workflow let attackers publish a second round of releases

To search the history of one repository for a suspicious string, Git has the git log -S option. For the tasks trick:

git log -S folderOpen

It lists the commits that added or removed the text folderOpen in the history of the repository you run it in. Look at each hit, and repeat the search in every repository you own that your agent or your tokens could reach.

If a bad pull request was merged, GitHub can revert it: near the bottom of the pull request, click Revert, which creates a new pull request that reverts the merge commit and needs write permission. You may need to revert individual commits if the pull request causes conflicts or was not merged on GitHub. More on repo inspection is on GitHub malware repository.

06Where to look for the cause

On a developer's Mac, look for something that ran on it. Stealers take browser data, cookies and session tokens, poisoned extensions can harvest GitHub credentials, and fake job tests harvest API tokens and signing keys; the last is on fake job interview malware. A valid token pushed to a public repository or gist is revoked automatically, but only after it was exposed. If you hold crypto on the same Mac, read crypto wallet drained next.

07GitHub account hacked: what to remember

When a GitHub account is hacked, the order is: check the Mac, revoke sessions, tokens and keys from a clean device, turn on two-factor authentication, rotate what the tokens reached, and read your recent commits. Keep a record of which services used each token, since you will replace them one by one. Anything that used an old token, such as a script, a CI job or an agent, will need the new one before it works again. A short outage on those is the cheaper price than an attacker holding a working token.

If the token left through your Mac, the cause ran there first; Artificial Immunity's free, open-source core watches program starts and reports what it finds.

FAQ

Can a GitHub account be hacked?

Yes. Stolen tokens and cookies can be used to impersonate the victim and reach everything the victim could, and GlassWorm harvested GitHub credentials, npm tokens and OpenVSX tokens.

How do I get my GitHub account back?

If you can still sign in, follow the order below, starting with the Mac. If you lost your two-factor credentials, you can use your recovery codes or another recovery option to regain access; the steps below apply once you are back in.

What to do if your account is compromised?

Check the Mac first, then revoke sessions, tokens and SSH keys from a clean device, turn on two-factor authentication, rotate the secrets the old tokens could reach, and look through your repositories for commits you did not make.

Why check the Mac before revoking tokens?

On Macs infected by the Mini Shai-Hulud npm malware, a background program polls GitHub every 60 seconds and, when it gets an error because its token was revoked, tries to run rm -rf ~/, which deletes the home folder. Look for ~/Library/LaunchAgents/com.user.gh-token-monitor.plist first; if it is there, stop that program or wait until it exits after 24 hours, then revoke.

How fast do attackers use a leaked token?

Automated scanners can locate publicly exposed secrets in minutes, and they can be exploited within hours. Act on a suspected leak the same day.

Does deleting the token from the repo fix it?

No. It is not sufficient to remove the secret from your codebase; the most important step is revoking it with the provider.

What if my GitHub account is compromised and I use Claude Code or Cursor?

In auto mode, Claude Code is allowed by default to push to any branch of the repository it works in, including the default branch. Review recent pushes with that in mind.

Sources

  1. GitHub docs, token expiration and revocation
  2. GitHub docs, managing personal access tokens
  3. GitHub docs, remediating a leaked secret
  4. GitHub docs, removing sensitive data from a repository
  5. GitHub docs, reverting a pull request
  6. Microsoft Entra, token theft
  7. Microsoft Defender Experts, hunting infostealers on macOS
  8. Wiz, Mini Shai-Hulud
  9. Veracode, GlassWorm
  10. AWS security bulletin AWS-2025-015
  11. PyPI blog, ultralytics attack analysis
  12. OpenSourceMalware, TasksJacker
  13. Artificial Immunity
  14. Cursor security notice, rotate from a trusted system
  15. GitHub docs, revoking your credentials
  16. GitHub docs, viewing and managing your sessions
  17. GitHub docs, reviewing your SSH keys
  18. GitHub docs, reviewing your authorized OAuth apps
  19. GitHub docs, recovering your account if you lose your 2FA credentials
Worried a stealer took your GitHub tokens? Artificial Immunity watches the Mac where your agents work.Get the free core