{"incident":{"slug":"nx-aug-2025-s1ngularity-npm-attack","caseId":"BI-2025-008","organization":"Nx","title":"Nx (s1ngularity): a PR title injection stole an npm token and weaponized local AI CLIs","shortSummary":"Attackers exploited a pull_request_target PR-title injection in Nx to steal NPM_TOKEN, publish tampered npm packages for four hours, and abuse local Claude and Gemini CLIs to hunt developer secrets.","lede":"On August 26, 2025, attackers chained three GitHub Actions settings inside the Nx monorepo project (pull_request_target, legacy read/write token defaults, and workflow_dispatch on publish.yml) to steal Nx’s npm publishing token. For four hours, tampered releases across eight nx versions and seven companion packages ran a postinstall script that invoked local AI CLI tools (Claude, Gemini, Amazon Q) to scan developer disks and upload secrets to public s1ngularity-repository repos. Nx Cloud was unaffected.","incidentDate":"Aug 26, 2025","incidentDateIso":"2025-08-26","disclosedDate":"Sep 5, 2025","sourceUrl":"https://nx.dev/blog/s1ngularity-postmortem","sourceAuthor":"Nx Official Postmortem and GHSA-cxm3-wv7p-598c","vectorFilter":"CI supply chain","timeToDetect":"~4 hours (packages unpublished Aug 26, 2025)","detectedBy":"Community reports and missing npm provenance attestations","initialAccess":{"label":"pull_request_target PR title injection","detail":"Unsanitized PR title echoing in a pull_request_target workflow ran shell commands with a read/write GITHUB_TOKEN","evidence":"confirmed"},"blastRadius":"8 nx releases + 7 companion packages (~6M weekly installs); thousands of leaked dev secrets","whatItReachedShort":"nx (20.9.0–20.12.0, 21.5.0–21.8.0) and companion @nx/* npm packages; developer SSH keys, tokens, and .env files pushed to public s1ngularity-repository GitHub repos","whatHeldShort":"Nx Cloud production platform, Nx Enterprise infrastructure, and the official CI release pipeline itself (tampered builds lacked npm provenance)","revisions":[{"id":"Rev A","date":"Sep 5, 2025","note":"Published from Nx’s September 5, 2025 official postmortem (nx.dev/blog/s1ngularity-postmortem) and GHSA-cxm3-wv7p-598c."}],"bodyMarkdown":"## How they got in\n\nNx's September 5, 2025 postmortem is a textbook illustration of how three individually mundane GitHub settings turn into full registry compromise.\n\nFirst, a PR-title validation workflow ran on `pull_request_target` (which executes with target-branch permissions and secrets) and echoed the untrusted PR title directly into a shell command. Second, because the repository pre-dated February 2023, it still carried GitHub's old default setting of \"Read and write permissions\" for Actions tokens. Third, `publish.yml` had `workflow_dispatch` enabled so maintainers could trigger manual runs.\n\nChaining those three together took minutes. The attacker opened a PR with shell commands in its title, used the read/write `GITHUB_TOKEN` to push a temporary branch swapping a CI script, triggered `publish.yml` against that branch through the GitHub API to steal `NPM_TOKEN`, and deleted the branch and workflow run to clean up.\n\n## What it reached\n\nWith `NPM_TOKEN` in hand, the attacker bypassed Nx's CI completely and pushed tampered releases directly to npm across `nx` (`20.9.0`–`20.12.0`, `21.5.0`–`21.8.0`), `@nx/devkit`, `@nx/js`, `@nx/workspace`, `@nx/node` (`20.9.0`, `21.5.0`), `@nx/eslint` (`21.5.0`), and `@nx/key` and `@nx/enterprise-cloud` (`3.2.0`).\n\nThe postinstall payload (`telemetry.js`) introduced a twist security teams had never seen at scale: it hunted for local AI coding CLIs (Claude Code, Gemini CLI, Amazon Q) and invoked them with permission-bypassing flags to recursively locate credentials, keys, and tokens across the filesystem. Harvested secrets were encoded into `results.b64` and uploaded using the developer's own GitHub CLI to newly created public repositories named `s1ngularity-repository*`, while some variants appended `sudo shutdown -h 0` to `~/.bashrc` and `~/.zshrc`.\n\n## What held\n\nBecause the rogue packages lacked npm provenance signing, Nx immediately knew its official CI release pipeline had not built them. Within four hours, npm pulled every tampered package and revoked all Nx tokens, while GitHub took down leaked repositories. Nx Cloud was architecturally isolated from open-source npm publishing and stayed completely untouched.\n\n> **Why this matters for defenders**\n>\n> Check `/settings/actions` on every repository created before February 2023: GitHub never retroactively downgraded legacy repos from read/write to read-only `GITHUB_TOKEN` permissions. Combine read-only defaults with npm OIDC Trusted Publishing and mandatory 2FA release approval so a single workflow bug can never steal a static publish token.","narrative":{"howTheyGotIn":["Nx's September 5, 2025 postmortem is a textbook illustration of how three individually mundane GitHub settings turn into full registry compromise.","First, a PR-title validation workflow ran on `pull_request_target` (which executes with target-branch permissions and secrets) and echoed the untrusted PR title directly into a shell command. Second, because the repository pre-dated February 2023, it still carried GitHub's old default setting of \"Read and write permissions\" for Actions tokens. Third, `publish.yml` had `workflow_dispatch` enabled so maintainers could trigger manual runs.","Chaining those three together took minutes. The attacker opened a PR with shell commands in its title, used the read/write `GITHUB_TOKEN` to push a temporary branch swapping a CI script, triggered `publish.yml` against that branch through the GitHub API to steal `NPM_TOKEN`, and deleted the branch and workflow run to clean up."],"whatItReached":["With `NPM_TOKEN` in hand, the attacker bypassed Nx's CI completely and pushed tampered releases directly to npm across `nx` (`20.9.0`–`20.12.0`, `21.5.0`–`21.8.0`), `@nx/devkit`, `@nx/js`, `@nx/workspace`, `@nx/node` (`20.9.0`, `21.5.0`), `@nx/eslint` (`21.5.0`), and `@nx/key` and `@nx/enterprise-cloud` (`3.2.0`).","The postinstall payload (`telemetry.js`) introduced a twist security teams had never seen at scale: it hunted for local AI coding CLIs (Claude Code, Gemini CLI, Amazon Q) and invoked them with permission-bypassing flags to recursively locate credentials, keys, and tokens across the filesystem. Harvested secrets were encoded into `results.b64` and uploaded using the developer's own GitHub CLI to newly created public repositories named `s1ngularity-repository*`, while some variants appended `sudo shutdown -h 0` to `~/.bashrc` and `~/.zshrc`."],"whatHeld":["Because the rogue packages lacked npm provenance signing, Nx immediately knew its official CI release pipeline had not built them. Within four hours, npm pulled every tampered package and revoked all Nx tokens, while GitHub took down leaked repositories. Nx Cloud was architecturally isolated from open-source npm publishing and stayed completely untouched."],"sideNoteTitle":"Why this matters for defenders","sideNoteParagraphs":["Check `/settings/actions` on every repository created before February 2023: GitHub never retroactively downgraded legacy repos from read/write to read-only `GITHUB_TOKEN` permissions. Combine read-only defaults with npm OIDC Trusted Publishing and mandatory 2FA release approval so a single workflow bug can never steal a static publish token."]},"claims":[{"group":"How they got in","claim":"Three conditions aligned: pull_request_target with unsanitized PR title echoing, legacy read/write Actions default permissions, and workflow_dispatch enabled on publish.yml","evidence":"confirmed","source":"Nx Official Postmortem, Sep 5, 2025"},{"group":"What it reached","claim":"Tampered versions included nx 20.9.0–20.12.0 and 21.5.0–21.8.0, @nx/devkit, @nx/js, @nx/workspace, @nx/node (20.9.0, 21.5.0), @nx/eslint (21.5.0), and @nx/key and @nx/enterprise-cloud (3.2.0)","evidence":"confirmed","source":"Nx Official Postmortem and GHSA-cxm3-wv7p-598c"},{"group":"What it reached","claim":"Postinstall payloads abused local AI CLI tools (such as Claude and Gemini), pushed secrets as results.b64 into public s1ngularity-repository GitHub repos, and appended sudo shutdown -h 0 to ~/.bashrc and ~/.zshrc","evidence":"confirmed","source":"Nx Official Postmortem and GHSA-cxm3-wv7p-598c"},{"group":"What held","claim":"Nx Cloud was never affected and remained fully operational and isolated from OSS npm releases","evidence":"confirmed","source":"Nx Official Postmortem, Sep 5, 2025"}],"diagram":{"label":"How a PR title injection in Nx stole NPM_TOKEN and turned local AI coding CLIs into secret harvesters","zones":[{"id":"ext","label":"External pull request","kind":"boundary","lane":0},{"id":"ci","label":"Nx GitHub Actions & npm","kind":"boundary","lane":1},{"id":"dev","label":"Developer & CI machines","kind":"boundary","lane":2},{"id":"safe","label":"Hosted platform","kind":"isolated","lane":2}],"nodes":[{"id":"nx-pr","zone":"ext","name":"Malicious PR title","detail":"Shell command payload","kind":"attacker","ev":"confirmed","at":0,"when":"Aug 26, 2025","steps":[1],"story":"An attacker opened a pull request whose title contained shell metacharacters targeting an unsanitized PR-title validation workflow running under pull_request_target."},{"id":"nx-ci","zone":"ci","name":"Read/write GITHUB_TOKEN","detail":"Triggered publish.yml","kind":"compromised","ev":"confirmed","at":1,"when":"Aug 26, 2025","steps":[1,2],"ctl":["nx-k1"],"story":"Because the repo still carried GitHub’s pre-2023 read/write default, the script pushed a rogue branch and dispatched publish.yml to steal NPM_TOKEN before deleting its tracks."},{"id":"nx-npm","zone":"ci","name":"Tampered nx on npm","detail":"8 nx + 7 @nx/* builds","kind":"compromised","ev":"confirmed","at":2,"when":"Aug 26 (4h window)","steps":[2,3],"ctl":["nx-k2"],"story":"Bypassing CI, the attacker pushed nx 20.9.0–20.12.0, 21.5.0–21.8.0, and companion @nx/* packages directly to npm without provenance signing for four hours."},{"id":"nx-ai","zone":"dev","name":"Postinstall & AI CLIs","detail":"s1ngularity-repository","kind":"compromised","ev":"confirmed","at":3,"when":"Aug 26, 2025","steps":[3],"ctl":["nx-k3"],"story":"The telemetry.js postinstall script invoked local Claude, Gemini, and Amazon Q CLIs with permission-skip flags to find secrets, uploaded results.b64 to public GitHub repos, and appended sudo shutdown -h 0 to shell profiles."},{"id":"nx-safe","zone":"safe","name":"Nx Cloud platform","detail":"Isolated from OSS npm","kind":"isolated","ev":"confirmed","at":0,"when":"Not reached","story":"Nx Cloud stayed fully operational and untouched throughout the four-hour OSS npm incident."}],"edges":[{"id":"nxe1","from":"nx-pr","to":"nx-ci","kind":"attack","step":1},{"id":"nxe2","from":"nx-ci","to":"nx-npm","kind":"attack","step":2},{"id":"nxe3","from":"nx-npm","to":"nx-ai","kind":"attack","step":3}],"steps":[{"n":1,"time":"Aug 26, 2025","short":"PR title inject","text":"Shell commands in a PR title execute under pull_request_target with write token","say":"A malicious PR title triggers command injection in Nx’s PR-title validation job, exposing a legacy read/write GITHUB_TOKEN."},{"n":2,"time":"Aug 26, 2025","short":"NPM_TOKEN stolen","text":"Attacker pushes a rogue branch, dispatches publish.yml, and publishes to npm","say":"Using workflow_dispatch on publish.yml, the attacker steals NPM_TOKEN, wipes the branch and workflow run, and publishes tampered nx and @nx/* packages lacking provenance."},{"n":3,"time":"Aug 26, 2025 (4 hours)","short":"4h npm window","text":"Postinstall abuses local AI CLIs and leaks secrets to s1ngularity-repository repos","say":"Infected developer machines run telemetry.js, abuse local AI CLIs to inventory sensitive files, publish base64 dumps to public GitHub repos, and sabotage shell startup files until npm pulls all bad versions four hours later."}],"controls":[{"id":"nx-k1","step":1,"kind":"control","nodeId":"nx-ci","name":"Default read-only token","tag":"Stops step 1","long":"Set repository Actions workflow permissions to read-only by default, avoid pull_request_target on untrusted PR metadata, and pass titles through env vars instead of inline shell interpolation."},{"id":"nx-k2","step":2,"kind":"control","nodeId":"nx-npm","name":"OIDC Trusted Publisher","tag":"Stops step 2","long":"Delete static NPM_TOKEN secrets, enable npm Trusted Publishers with OIDC, and require manual environment approval with 2FA before any release publishes."},{"id":"nx-k3","step":3,"kind":"detection","nodeId":"nx-ai","name":"Block install scripts","tag":"Catches step 3","long":"Disable npm lifecycle scripts by default (ignore-scripts=true) and alert on unexpected public GitHub repo creations or shell profile edits (sudo shutdown -h 0)."}],"detectedAt":{"time":"Aug 26, 2025 (~4 hours after first publish)","short":"Aug 26 (4h)","text":"Missing npm provenance signatures confirmed the packages did not originate from Nx CI; npm removed every tampered version and revoked all Nx npm tokens within four hours."}},"plate":{"W":799,"H":380,"label":"How a PR title injection in Nx stole NPM_TOKEN and turned local AI coding CLIs into secret harvesters","zones":[{"id":"ext","label":"External pull request","kind":"boundary","x":8,"y":16,"w":208,"h":110},{"id":"ci","label":"Nx GitHub Actions & npm","kind":"boundary","x":254,"y":16,"w":267,"h":212},{"id":"dev","label":"Developer & CI machines","kind":"boundary","x":559,"y":16,"w":232,"h":110},{"id":"safe","label":"Hosted platform","kind":"isolated","x":559,"y":146,"w":232,"h":110}],"nodes":[{"id":"nx-pr","name":"Malicious PR title","detail":"Shell command payload","kind":"attacker","ev":"confirmed","x":20,"y":52,"w":184,"at":0,"story":"An attacker opened a pull request whose title contained shell metacharacters targeting an unsanitized PR-title validation workflow running under pull_request_target.","when":"Aug 26, 2025","steps":[1]},{"id":"nx-ci","name":"Read/write GITHUB_TOKEN","detail":"Triggered publish.yml","kind":"compromised","ev":"confirmed","x":266,"y":52,"w":243,"at":1,"story":"Because the repo still carried GitHub’s pre-2023 read/write default, the script pushed a rogue branch and dispatched publish.yml to steal NPM_TOKEN before deleting its tracks.","when":"Aug 26, 2025","steps":[1,2],"ctl":["nx-k1"]},{"id":"nx-npm","name":"Tampered nx on npm","detail":"8 nx + 7 @nx/* builds","kind":"compromised","ev":"confirmed","x":266,"y":154,"w":243,"at":2,"story":"Bypassing CI, the attacker pushed nx 20.9.0–20.12.0, 21.5.0–21.8.0, and companion @nx/* packages directly to npm without provenance signing for four hours.","when":"Aug 26 (4h window)","steps":[2,3],"ctl":["nx-k2"]},{"id":"nx-ai","name":"Postinstall & AI CLIs","detail":"s1ngularity-repository","kind":"compromised","ev":"confirmed","x":571,"y":52,"w":208,"at":3,"story":"The telemetry.js postinstall script invoked local Claude, Gemini, and Amazon Q CLIs with permission-skip flags to find secrets, uploaded results.b64 to public GitHub repos, and appended sudo shutdown -h 0 to shell profiles.","when":"Aug 26, 2025","steps":[3],"ctl":["nx-k3"]},{"id":"nx-safe","name":"Nx Cloud platform","detail":"Isolated from OSS npm","kind":"isolated","ev":"confirmed","x":581,"y":182,"w":188,"at":0,"story":"Nx Cloud stayed fully operational and untouched throughout the four-hour OSS npm incident.","when":"Not reached"}],"edges":[{"id":"nxe1","kind":"attack","step":1,"pts":[[204,81],[266,81]]},{"id":"nxe2","kind":"attack","step":2,"pts":[[388,110],[388,154]]},{"id":"nxe3","kind":"attack","step":3,"pts":[[509,183],[540,183],[540,81],[571,81]]}],"balloons":{"1":[235,81],"2":[388,132],"3":[540,132]},"noroute":[{"x1":521,"x2":559,"y":188,"label":"No route"}],"bps":[{"id":"nx-k1","step":1,"kind":"control","at":[235,81],"name":"Default read-only token","tag":"Stops step 1","lead":[[235,70],[235,53],[247,53]],"lx":253,"ly":57,"anchor":"start","long":"Set repository Actions workflow permissions to read-only by default, avoid pull_request_target on untrusted PR metadata, and pass titles through env vars instead of inline shell interpolation.","nodeId":"nx-ci"},{"id":"nx-k2","step":2,"kind":"control","at":[388,132],"name":"OIDC Trusted Publisher","tag":"Stops step 2","lead":[[388,143],[388,154],[400,154]],"lx":406,"ly":158,"anchor":"start","long":"Delete static NPM_TOKEN secrets, enable npm Trusted Publishers with OIDC, and require manual environment approval with 2FA before any release publishes.","nodeId":"nx-npm"},{"id":"nx-k3","step":3,"kind":"detection","at":[540,132],"name":"Block install scripts","tag":"Catches step 3","lead":[[540,121],[540,104],[528,104]],"lx":522,"ly":108,"anchor":"end","long":"Disable npm lifecycle scripts by default (ignore-scripts=true) and alert on unexpected public GitHub repo creations or shell profile edits (sudo shutdown -h 0).","nodeId":"nx-ai"}],"steps":[{"n":1,"time":"Aug 26, 2025","short":"PR title inject","text":"Shell commands in a PR title execute under pull_request_target with write token","say":"A malicious PR title triggers command injection in Nx’s PR-title validation job, exposing a legacy read/write GITHUB_TOKEN."},{"n":2,"time":"Aug 26, 2025","short":"NPM_TOKEN stolen","text":"Attacker pushes a rogue branch, dispatches publish.yml, and publishes to npm","say":"Using workflow_dispatch on publish.yml, the attacker steals NPM_TOKEN, wipes the branch and workflow run, and publishes tampered nx and @nx/* packages lacking provenance."},{"n":3,"time":"Aug 26, 2025 (4 hours)","short":"4h npm window","text":"Postinstall abuses local AI CLIs and leaks secrets to s1ngularity-repository repos","say":"Infected developer machines run telemetry.js, abuse local AI CLIs to inventory sensitive files, publish base64 dumps to public GitHub repos, and sabotage shell startup files until npm pulls all bad versions four hours later."}],"stripRows":[{"id":"sr-nx-pr","nodeId":"nx-pr","lineStyle":"solid"},{"id":"sr-step-1","nodeId":"nx-ci","step":1,"lineStyle":"solid","bpIds":["nx-k1"]},{"id":"sr-step-2","nodeId":"nx-npm","step":2,"lineStyle":"solid","bpIds":["nx-k2"]},{"id":"sr-step-3","nodeId":"nx-ai","step":3,"lineStyle":"none","bpIds":["nx-k3"]}],"detectedAt":{"time":"Aug 26, 2025 (~4 hours after first publish)","short":"Aug 26 (4h)","text":"Missing npm provenance signatures confirmed the packages did not originate from Nx CI; npm removed every tampered version and revoked all Nx npm tokens within four hours."}},"codeArtifacts":[{"id":"nx-host-check","filename":"check-s1ngularity-iocs.sh","language":"sh","description":"Inspect a developer workstation for s1ngularity shell sabotage and temporary inventory files.","code":"#!/usr/bin/env bash\nset -euo pipefail\ngrep -n \"sudo shutdown -h 0\" ~/.bashrc ~/.zshrc 2>/dev/null || echo \"Shell profiles clean\"\nls -la /tmp/inventory.txt /tmp/inventory.txt.bak 2>/dev/null || echo \"No /tmp/inventory.txt artifact\"\ngh repo list --limit 100 --json name --jq '.[].name | select(startswith(\"s1ngularity-repository\"))' 2>/dev/null || true\n"}],"reproductionLab":{"title":"Workflow & workstation s1ngularity audit","summary":"Check GitHub repository default Actions permissions (read-only vs. legacy read/write) and scan developer machines for s1ngularity artifacts.","bundleMeta":"Shell check script, MIT license","safetyNote":"Read-only local inspection and GitHub repo listing.","commands":"bash check-s1ngularity-iocs.sh\n"},"iocs":[{"type":"Repository","value":"s1ngularity-repository* (results.b64)","note":"Public GitHub repositories created under victim accounts containing base64-encoded secrets","evidence":"confirmed"},{"type":"File","value":"/tmp/inventory.txt","note":"Temporary local file inventory created by the postinstall harvester","evidence":"confirmed"},{"type":"Command","value":"sudo shutdown -h 0 in ~/.bashrc or ~/.zshrc","note":"Sabotage command appended to developer shell startup scripts","evidence":"confirmed"}],"publishedAt":"2025-09-05T16:00:00Z","origin":"editorial"}}