These write-ups are not threat intelligence and are not kept up to date as an incident develops. They are here to show how each attack worked, so you can find and fix the same techniques in your own setup. For the latest on an incident, read its sources.
Heroku / Travis CI OAuth token theft
April 2022 · Contained
OAuth tokens stolen from Heroku, and tokens of the Travis CI app, let the attacker clone private repositories of dozens of organizations, npm among them, without ever breaking into GitHub.
- Went after
- Read or expose private code
- Access held
- Read the rest
- GitHub security alert: stolen OAuth user tokens ↗
Full summary
The attacker never broke into GitHub. They broke into Heroku. A token for a Heroku machine account was sitting in an archived private Heroku repository, which Heroku believes was read through a third-party integration it could never name. With that token the attacker got into a Heroku database on 7 April 2022 and downloaded the GitHub OAuth tokens Heroku stored for every customer who had connected the Heroku Dashboard to GitHub. Tokens issued to the Travis CI OAuth app were also used; how they were taken is not stated. On 8 April the attacker used the tokens against the GitHub API to list each user's organizations and private repositories, picked targets, and from 9 April cloned private repositories of dozens of organizations, Heroku and npm among them. One npm repository held an AWS key. On 12 April GitHub caught that key being used against npm's production infrastructure, which is how the whole campaign came to light. GitHub believes the attacker was mining the cloned code for secrets to reach other systems.
How it unfolded
Pick a step to zoom into it. A dashed line is a step the sources do not state. Blue dots are the checklist items that break the step.
Whole path
The whole attack, one row per step. Pick a step on the left, or click a box in its row.
Before 7 April 2022 the attacker got a token for a Heroku machine account from an archived private GitHub repository with Heroku source code in it. Heroku assessed that the repository was read through a third-party integration, but could not confirm which one.
What breaks this step
- Set an organization-wide maximum PAT lifetime (90 days is a reasonable default)
- Disable classic PATs organization-wide, forcing migration to fine-grained PATs
- Audit and revoke stale PATs, unused SSH keys, and inactive accounts
- Enforce an IP allow list for Git and web UI access from trusted ranges
- Service-account automation migrated from PATs to GitHub Apps
On 7 April the attacker used the machine account token to reach a Heroku database and download the GitHub OAuth tokens stored for customers of the Heroku Dashboard GitHub integration. The same day they downloaded a database of pipeline config vars for Review Apps and Heroku CI, and, with the same token, the hashed and salted passwords of Heroku user accounts. Tokens of the Travis CI OAuth app were abused too. Travis CI said the attacker took a private OAuth key linking Heroku and Travis CI from a Heroku service, and that it gave no access to customer repositories.
What breaks this step
- Review every currently installed GitHub App / OAuth App and its granted scope
- Keep OAuth app access restrictions on and require security/IT approval for new apps
- Maintain a documented list of allowed apps, their use case, and their owner
- Scope installations to specific repositories rather than all repositories.
From 8 April the attacker called the GitHub API with the stolen tokens. For most users who had authorized the apps they listed every organization the user belonged to, picked organizations of interest, then listed private repositories through /user/repos and /orgs/{org}/repos. GitHub called the attack highly targeted.
From 9 April the attacker cloned some of those private repositories: a subset of Heroku's own, through a Heroku employee's compromised OAuth token, and those of dozens of other organizations, including npm. One of npm's private repositories held an AWS access key.
What breaks this step
- Set an organization-wide maximum PAT lifetime (90 days is a reasonable default)
- Disable classic PATs organization-wide, forcing migration to fine-grained PATs
- Audit and revoke stale PATs, unused SSH keys, and inactive accounts
- Enforce an IP allow list for Git and web UI access from trusted ranges
- Service-account automation migrated from PATs to GitHub Apps
With the AWS key the attacker reached npm's production infrastructure and took a backup of skimdb.npmjs.com from 7 April 2021 with metadata for every public and private package, a 2015 archive with about 100,000 npm user names, email addresses and password hashes, listings of the package buckets as of 10 April 2022, and the contents of some private packages of two organizations. GitHub found no modified or newly published packages.
GitHub spotted the AWS key in use on 12 April, told Heroku and Travis CI on 13 April and revoked the tokens of its own and npm's use of the apps. It named the five OAuth apps on 15 April: Heroku Dashboard (two app IDs), Heroku Dashboard Preview, Heroku Dashboard Classic and Travis CI. Heroku finished revoking every token of its GitHub integration at 5 p.m. PT on 16 April and kept the integration off until 25 May. Travis CI revoked and reissued every token linking it to GitHub.
GitHub emailed organizations whose repositories were cloned by 18 April, those whose repositories were only listed by 22 April, and every remaining user of the two integrations by 27 April. npm reset the affected passwords and finished its notifications on 2 June. Heroku reset all user passwords by 5 May and saw no further activity by the attacker after 14 April.
Frameworks
Contained. First seen April 2022. Mapping by ghtier, not yet reviewed. Threat landscape
Sources
- postmortemGitHub security alert: stolen OAuth user tokens
- postmortemnpm security update: attack campaign using stolen OAuth tokens
- postmortemHeroku security notification (incident 2413)
- postmortemHeroku: April 2022 incident review
- postmortemTravis CI security bulletin: customer repositories have not been accessed
- trackerGitHub and npm incident (Wiz Cloud Threat Landscape)