@testzugang/pi-plugin-dependency-audit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @testzugang/pi-plugin-dependency-audit
2
+
3
+ Static dependency and supply-chain malware auditing skill for Pi.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@testzugang/pi-plugin-dependency-audit
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```text
14
+ /skill:dependency-audit
15
+ ```
16
+
17
+ ## Interactive Terminal Integration (Wrapper)
18
+
19
+ See [SKILL.md](skills/dependency-audit/SKILL.md) for full instructions on setting up automated shell interception for security checks on `pi update`.
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@testzugang/pi-plugin-dependency-audit",
3
+ "version": "0.1.0",
4
+ "description": "Static dependency and supply-chain malware auditing skill for Pi",
5
+ "keywords": ["pi-package"],
6
+ "license": "MIT",
7
+ "files": [
8
+ "skills",
9
+ "README.md"
10
+ ],
11
+ "pi": {
12
+ "skills": [
13
+ "./skills"
14
+ ]
15
+ },
16
+ "peerDependencies": {
17
+ "@earendil-works/pi-coding-agent": "*"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public",
21
+ "provenance": true
22
+ }
23
+ }
@@ -0,0 +1,105 @@
1
+ # npm/TypeScript Package Audit Skill
2
+
3
+ Static-first Skill for reviewing TypeScript dependencies, npm packages and npm-based repositories before install or use.
4
+
5
+ ## What it does
6
+
7
+ - Scans `package.json`, npm/pnpm/yarn lockfiles, `.npmrc`, TypeScript config, GitHub Actions and TS/JS source files.
8
+ - Detects risky npm lifecycle scripts, Git/URL/File dependencies, optional dependency traps, bundled dependencies, non-default tarball sources and missing integrity.
9
+ - Scans npm `.tgz` tarballs without executing package code.
10
+ - Flags malware patterns such as download+execute, credential access+network, obfuscation, cloud metadata probes, GitHub API write behavior and IDE/AI-agent persistence.
11
+ - Produces Markdown, JSON and SARIF output.
12
+
13
+ ## Quick start
14
+
15
+ ```bash
16
+ python3 scripts/npm_ts_static_triage.py /path/to/repo-or-package.tgz \
17
+ --mode package \
18
+ --markdown npm-ts-audit.md \
19
+ --json npm-ts-audit.json \
20
+ --sarif npm-ts-audit.sarif \
21
+ --strict-exit
22
+ ```
23
+
24
+ For global pi dependency checks without on-the-fly shell loops:
25
+
26
+ ```bash
27
+ bash scripts/pi-check-current-global-versions.sh
28
+ bash scripts/pi-check-latest-npm-versions.sh
29
+ bash scripts/pi-check-git-source-updates.sh
30
+ # or everything in one run
31
+ bash scripts/pi-check-all-updates.sh
32
+
33
+ # full static update audit + markdown summary
34
+ python3 scripts/run_pi_dependency_audit.py --output /tmp/pi_audit_aggregated.json
35
+ python3 scripts/summarize_pi_dependency_audit.py \
36
+ --input /tmp/pi_audit_aggregated.json \
37
+ --output /tmp/pi_audit_report.md
38
+ ```
39
+
40
+ Age-gate configuration (default: 24h):
41
+
42
+ - repo default: `skills/dependency-audit/config.json`
43
+ - user override: `~/.pi/dependency-audit.json`
44
+ - highest priority override: `--config /path/to/config.json`
45
+
46
+ Example config:
47
+
48
+ ```json
49
+ {
50
+ "min_update_age_hours": 24
51
+ }
52
+ ```
53
+
54
+ `--strict-exit` exits with code `2` for HIGH/CRITICAL findings and `1` for MEDIUM-only findings.
55
+
56
+ ## Safe package acquisition
57
+
58
+ ```bash
59
+ npm view <package>@<version> name version dist.tarball dist.integrity dist.shasum time maintainers repository license --json
60
+ curl -fL -o package-under-review.tgz '<dist.tarball-url>'
61
+ sha256sum package-under-review.tgz
62
+ python3 scripts/npm_ts_static_triage.py package-under-review.tgz --markdown report.md --json report.json --strict-exit
63
+ ```
64
+
65
+ Do not run `npm install`, `npm ci`, `npm pack`, `npm test`, `npm run build`, `npx`, `node`, `tsx` or `ts-node` against untrusted code before static review.
66
+
67
+ ## Files
68
+
69
+ - `SKILL.md`: full German skill instructions and policy.
70
+ - `scripts/npm_ts_static_triage.py`: standalone stdlib-only scanner.
71
+ - `scripts/pi-check-current-global-versions.sh`: reads installed versions for default/global pi packages.
72
+ - `scripts/pi-check-latest-npm-versions.sh`: reads latest npm registry versions for default/global pi packages.
73
+ - `scripts/pi-check-git-source-updates.sh`: compares local git checkouts with origin branch heads.
74
+ - `scripts/pi-check-all-updates.sh`: runs all three checks in sequence.
75
+ - `scripts/pi-default-packages.txt`: default package target list for the helper scripts.
76
+ - `scripts/pi-default-git-repos.txt`: default git repo target list for update checks.
77
+ - `scripts/run_pi_dependency_audit.py`: end-to-end static audit workflow for global pi dependency updates.
78
+ - `scripts/summarize_pi_dependency_audit.py`: creates a markdown summary from aggregated JSON results.
79
+ - `scripts/pi-interactive-update.py`: interactive CLI wrapper and menu selector for native `pi update` integration.
80
+ - `config.json`: default config (currently `min_update_age_hours`).
81
+ - `rules/iocs.txt`: editable IOC seed list.
82
+ - `templates/report.md`: manual review template.
83
+ - `examples/sample-commands.md`: safe commands and review playbooks.
84
+ - `examples/github-actions-static-audit.yml`: example CI workflow for static-only scanning.
85
+
86
+ ## Interactive Shell Wrapper (`pi update` integration)
87
+
88
+ To intercept the native `pi update` command in your terminal so it automatically runs this security audit first and prompts you with a selection menu of verified-safe updates, add the following wrapper function to your shell configuration (e.g., `~/.zshrc` or `~/.bashrc`):
89
+
90
+ ```bash
91
+ # Wrapper for pi update to prepend dependency-audit and trigger interactive CLI selection
92
+ pi() {
93
+ if [[ "$1" == "update" && ( -z "$2" || "$2" == "--extensions" ) ]]; then
94
+ python3 ~/.pi/agent/git/github.com/testzugang/pi-plugins/skills/dependency-audit/scripts/pi-interactive-update.py
95
+ else
96
+ command pi "$@"
97
+ fi
98
+ }
99
+ ```
100
+
101
+ After reloading your shell (`source ~/.zshrc`), typing `pi update` or `pi update --extensions` will launch the interactive audit menu before running any updates.
102
+
103
+ ## Important limitation
104
+
105
+ A clean static report is not proof of safety. Use it as a pre-installation gate and combine it with registry metadata review, version cooldown, script suppression, provenance/signature checks, sandboxing and human review.
@@ -0,0 +1,353 @@
1
+ ---
2
+ name: dependency-audit
3
+ description: Use when you need to audit an npm package, a GitHub repository, or pending dependency updates for supply-chain malware and risky lifecycle scripts before installation. Default action without parameters is to audit all pending updates.
4
+ ---
5
+
6
+ # npm/TypeScript Package & Dependency Audit Skill
7
+
8
+ ## Ziel
9
+
10
+ Nutze diesen Skill, wenn TypeScript-/JavaScript-Code, ein npm-Paket, ein GitHub-Repository, ein Dependency-Update oder ein npm-Lockfile vor der Nutzung geprüft werden soll. Der Fokus liegt auf Malware- und Supply-Chain-Erkennung vor `npm install`, `npm ci`, Build, Test, Import oder IDE-/CI-Ausführung.
11
+
12
+ ### Automatischer Workflow (ohne Parameter)
13
+
14
+ Wenn der Skill ohne weitere Parameter aufgerufen wird (z.B. `/skill:dependency-audit`), muss **immer zuerst** eine explizite Modus-Auswahl über `user_select` erfolgen.
15
+
16
+ Pflichtfrage (immer, als erster Schritt):
17
+
18
+ - **"Pi-Dependencies prüfen"**
19
+ - **"Projekt-Dependencies (aktuelles Verzeichnis) prüfen"**
20
+ - **"Beides prüfen"**
21
+
22
+ Regeln:
23
+
24
+ 1. Diese Auswahl darf nicht übersprungen werden, auch nicht bei fehlender `package.json`.
25
+ 2. Existiert bei Auswahl "Projekt-Dependencies" keine `package.json`, gib eine klare Rückfrage: Pfad angeben oder auf Pi-Dependencies wechseln.
26
+ 3. Starte keine Prüfung, bevor der Nutzer einen der drei Modi bestätigt hat.
27
+
28
+ Führe dann je nach Auswahl die entsprechenden Szenarien aus:
29
+
30
+ **Szenario A: Lokale npm-Abhängigkeiten**
31
+
32
+ 1. Führe `npm outdated --json` (oder ein äquivalentes Tool) aus, um die Liste verfügbarer Updates zu ermitteln.
33
+ 2. Iteriere durch die ermittelten Pakete.
34
+ 3. Führe für jedes Paket die in diesem Skill beschriebenen statischen Prüfungen durch.
35
+ 4. Generiere einen aggregierten Report.
36
+
37
+ **Szenario B: Globale Pi-Erweiterungen**
38
+
39
+ 1. Nutze bevorzugt die mitgelieferten Hilfsskripte statt ad-hoc Bash-Loops:
40
+ - `scripts/pi-check-current-global-versions.sh`
41
+ - `scripts/pi-check-latest-npm-versions.sh`
42
+ - `scripts/pi-check-git-source-updates.sh`
43
+ - optional End-to-End: `scripts/run_pi_dependency_audit.py`
44
+ 2. Nutze die Config-Resolution für Sicherheitsrichtlinien (Priorität):
45
+ - `--config /path/to/config.json`
46
+ - `~/.pi/dependency-audit.json`
47
+ - `skills/dependency-audit/config.json`
48
+ - Fallback auf Defaults
49
+ 3. `min_update_age_hours` steuert die Mindest-Altersschwelle für Updates. Default ist `24`.
50
+ 4. Ermittle für jedes Paket, ob auf der Remote-Quelle (z. B. auf GitHub) neue Commits oder Versionen verfügbar sind.
51
+ 5. Wenn ein Update jünger als `min_update_age_hours` ist, markiere es als `too_fresh` mit `SKIP_TOO_FRESH`.
52
+ 6. Klone/lade die übrigen Updates temporär herunter, **ohne sie zu installieren oder Scripte auszuführen**.
53
+ 7. Führe die in diesem Skill beschriebenen statischen Prüfungen auf dem neuen Code durch.
54
+ 8. Generiere einen Report, der angibt, welche Pi-Erweiterungen sicher aktualisiert werden können. **Präsentiere am Ende des Berichts immer einen maßgeschneiderten nativen `pi update`-Vorschlag (siehe Abschnitt "Natives Pi-Paketmanagement (`pi update`)"), der blockierte/quarantänisierte oder zu frische Pakete explizit auslässt.**
55
+
56
+ ### Spezifischer Workflow (mit Parametern)
57
+
58
+ Wenn der Skill mit einem Paketnamen oder einer Repository-URL aufgerufen wird, fokussiere die Prüfung ausschließlich auf dieses Ziel. Lade den Code in ein temporäres Verzeichnis herunter und wende die Prüfphasen statisch an.
59
+
60
+ Der Skill ist bewusst auf npm und TypeScript zugeschnitten. Er prüft insbesondere:
61
+
62
+ - `package.json`, `package-lock.json`, `npm-shrinkwrap.json`, `pnpm-lock.yaml`, `yarn.lock`, `.npmrc`.
63
+ - npm-Lifecycle-Scripts wie `preinstall`, `install`, `postinstall`, `prepare`, `prepack`, `prepublish`.
64
+ - `optionalDependencies`, Git-/URL-/File-Dependencies, Aliase, Overrides und Resolutions.
65
+ - npm-Tarballs (`.tgz`) ohne Installation oder Script-Ausführung.
66
+ - TypeScript-/JavaScript-Quellen, `dist/`, `lib/`, CLI-`bin`-Entrypoints und minifizierte/obfuskierte Dateien.
67
+ - GitHub Actions und Publish-/Release-Workflows.
68
+ - IDE-/AI-Agent-Poisoning über `.vscode`, `.claude`, `.cursor`, `.devcontainer`.
69
+ - Qualität: Typisierung, `tsconfig`, Tests, Linting, Metadaten, Lockfile-Disziplin, Reproduzierbarkeit.
70
+
71
+ ## Threat Model
72
+
73
+ Behandle jedes unbekannte npm-Paket und jede neue Dependency-Version als potenziell feindlich. Typische npm-/TS-Angriffe sind:
74
+
75
+ 1. **Install-Time Malware**: `preinstall`, `postinstall` oder `prepare` startet einen Downloader, Bootstrapper oder Token-Stealer.
76
+ 2. **Git-Dependency-Falle**: Eine scheinbar harmlose Dependency zeigt auf GitHub. Beim Installieren kann npm ein `prepare`-Script dieser Git-Dependency ausführen.
77
+ 3. **Optional-Dependency-Versteck**: Bösartiger Code liegt in `optionalDependencies`, wird leicht übersehen und kann bei Fehlern weniger auffallen.
78
+ 4. **Tarball-Poisoning**: Der veröffentlichte npm-Tarball enthält zusätzliche Dateien, die nicht im GitHub-Repo sichtbar sind.
79
+ 5. **Compiled JS Payload**: TypeScript-Repo wirkt sauber, aber `dist/`, `lib/` oder `setup.mjs` enthält obfuskierten JavaScript-Code.
80
+ 6. **Credential Harvesting**: Code sucht nach `GITHUB_TOKEN`, `NPM_TOKEN`, AWS-/Vault-/GitHub-Actions-OIDC-Secrets oder lokalen Dateien wie `.npmrc`, `.aws/credentials`, `.config/gh/hosts.yml`.
81
+ 7. **Repo-/IDE-Persistence**: Malware schreibt `.vscode/tasks.json`, `.claude/settings.json` oder ähnliche Konfigurationen, damit andere Entwickler oder AI-Coding-Agents später Code ausführen.
82
+ 8. **CI/CD-Missbrauch**: Workflows führen untrusted Code mit Write-Rechten, npm-Publish-Token oder OIDC-Rechten aus.
83
+
84
+ ## Sicherheitsvertrag
85
+
86
+ Diese Regeln sind verbindlich:
87
+
88
+ 1. **Kein untrusted Code wird ausgeführt.** Kein `npm install`, `npm ci`, `npm test`, `npm run build`, `npx`, `pnpm install`, `yarn install`, `bun install`, `node setup.mjs`, `tsx`, `ts-node`, `docker build` oder ähnliches vor statischer Prüfung.
89
+ 2. **Kein `npm pack` aus einem untrusted Repo.** `npm pack` gehört zu den npm-Pack-Lifecycle-Abläufen und kann `prepack`, `prepare` und `postpack` betreffen. Für veröffentlichte Pakete lieber Registry-Metadaten lesen und den bereits veröffentlichten Tarball herunterladen.
90
+ 3. **Keine echten Secrets in der Analyseumgebung.** Vor der Prüfung keine GitHub-, npm-, AWS-, Azure-, GCP-, Vault- oder CI-Tokens exportieren.
91
+ 4. **Netzwerk ist standardmäßig aus.** Registry-/GitHub-Metadaten nur verwenden, wenn der Nutzer es erlaubt oder es zur Aktualitätsprüfung notwendig ist.
92
+ 5. **Artefakte immutable festhalten.** Repository immer auf exakten Commit-SHA; npm-Paket immer auf exakte Version und Tarball-Hash.
93
+ 6. **Script-Ausführung bleibt deaktiviert.** Review-Installationen nur mit `--ignore-scripts`, möglichst zusätzlich ohne optionale Dependencies.
94
+ 7. **Gefundene Secrets werden maskiert.** Nie komplette Tokens in Report, Chat, Logs oder Tickets ausgeben.
95
+ 8. **Jedes `CRITICAL` oder `HIGH` Finding blockiert Nutzung**, bis es manuell verifiziert, entfernt oder bewusst allowlisted wurde.
96
+
97
+ ## Eingaben
98
+
99
+ Erfrage oder bestimme:
100
+
101
+ - Paketname und Version, z. B. `@scope/pkg@1.2.3`, oder lokaler Repo-/Tarball-Pfad.
102
+ - Exakter Git-Commit oder Release-Tag.
103
+ - Nutzungsziel: Library, CLI, Frontend-App, Backend-Service, CI-Build, Production.
104
+ - Package Manager: npm, pnpm, yarn oder bun. Dieser Skill bewertet primär npm-Semantik; pnpm/yarn-Lockfiles werden statisch mitgeprüft.
105
+ - Ob Netzwerkzugriff für Registry-/GitHub-Metadaten erlaubt ist.
106
+ - Ob es ein Dependency-Update ist; falls ja: alte Version, neue Version und Diff-Kontext.
107
+
108
+ Wenn Angaben fehlen, führe eine konservative Best-Effort-Prüfung aus und dokumentiere Annahmen.
109
+
110
+ ## Ablauf
111
+
112
+ ### Phase 0: Secret-freie Analyseumgebung
113
+
114
+ Nutze ein separates Verzeichnis oder eine Sandbox. Entferne Tokens aus der Shell:
115
+
116
+ ```bash
117
+ unset GITHUB_TOKEN GH_TOKEN NPM_TOKEN NODE_AUTH_TOKEN AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN VAULT_TOKEN
118
+ ```
119
+
120
+ Optional: Netzwerk in der Sandbox blockieren, sobald Artefakte vorliegen.
121
+
122
+ ### Phase 1: Artefakt beschaffen, ohne Code auszuführen
123
+
124
+ #### GitHub-Repo
125
+
126
+ ```bash
127
+ GIT_LFS_SKIP_SMUDGE=1 git clone --no-checkout <repo-url> repo-under-review
128
+ cd repo-under-review
129
+ git checkout --detach <exact-commit-sha-or-tag>
130
+ git submodule status --recursive || true
131
+ ```
132
+
133
+ Prüfe sofort `.gitmodules`, Workspaces, `package.json`, Lockfiles und `.github/workflows`.
134
+
135
+ #### Veröffentlichtes npm-Paket
136
+
137
+ Metadaten lesen, ohne Installation:
138
+
139
+ ```bash
140
+ npm view <package>@<version> name version dist.tarball dist.integrity dist.shasum time maintainers repository license --json
141
+ ```
142
+
143
+ Tarball herunterladen und Hash festhalten. Beispiel:
144
+
145
+ ```bash
146
+ curl -fL -o package-under-review.tgz '<dist.tarball-url>'
147
+ sha256sum package-under-review.tgz
148
+ ```
149
+
150
+ Dann den Tarball mit dem mitgelieferten Scanner prüfen. Nicht installieren.
151
+
152
+ ### Phase 2: Automatisierte statische Triage
153
+
154
+ ```bash
155
+ python3 scripts/npm_ts_static_triage.py /path/to/repo-or-package.tgz \
156
+ --mode package \
157
+ --markdown npm-ts-audit.md \
158
+ --json npm-ts-audit.json \
159
+ --sarif npm-ts-audit.sarif \
160
+ --strict-exit
161
+ ```
162
+
163
+ Modi:
164
+
165
+ - `package`: Standard für npm-Paket/Tarball.
166
+ - `library`: TypeScript-Library; Version-Ranges sind weniger stark gewichtet, weil Libraries häufig Ranges nutzen.
167
+ - `application`: App/Service; fehlende Lockfiles und Floating Ranges sind stärker relevant.
168
+ - `repo`: allgemeines Repository-/Monorepo-Review.
169
+
170
+ Der Scanner führt keinen Zielcode aus. Er extrahiert `.tgz`-Dateien sicher, folgt keinen Symlinks, scannt `package.json`, Lockfiles, npmrc, TS/JS-Dateien, Workflows und bekannte IoCs.
171
+
172
+ ### Phase 3: `package.json` manuell prüfen
173
+
174
+ Blockiere oder eskaliere bei:
175
+
176
+ - Install-Phase-Scripts: `preinstall`, `install`, `postinstall`, `prepublish`, `prepare`, `preprepare`, `postprepare`, `dependencies`.
177
+ - Pack-/Publish-Scripts: `prepack`, `postpack`, `prepublishOnly`, `publish`, `postpublish`, wenn sie nicht trivial und dokumentiert sind.
178
+ - Script-Inhalte mit `curl`, `wget`, `fetch`, `axios`, `got`, `node -e`, `eval`, `new Function`, `child_process`, `execSync`, `spawn`, `bun`, `python`, `bash`, `powershell`, `chmod +x`, Base64-/zlib-/AES-Decodern.
179
+ - Kombinationen wie Download plus Execute, Secret-Zugriff plus Netzwerk oder `&& exit 1` nach Ausführung.
180
+ - `optionalDependencies` mit `github:`, `git+`, `http(s)://`, `file:`, `link:` oder `npm:` Alias.
181
+ - `overrides` oder `resolutions`, die transitive Dependencies auf Git-/URL-/File-Quellen umbiegen.
182
+ - `bundleDependencies`/`bundledDependencies`, besonders `true`.
183
+ - `bin`-Entrypoints, die auf obfuskierte oder fehlende Dateien zeigen.
184
+ - `publishConfig.registry`, `.npmrc` oder Package-Metadaten, die auf nicht erwartete Registries zeigen.
185
+
186
+ ### Phase 4: Lockfile- und Dependency-Prüfung
187
+
188
+ Prüfe:
189
+
190
+ - `package-lock.json`-Einträge mit `hasInstallScript: true`.
191
+ - `resolved`-Werte mit `git+`, `github:`, `http://`, nicht erwarteten Registries oder lokalen `file:`-Quellen.
192
+ - Fehlende `integrity`-Werte bei Registry-Tarballs.
193
+ - `optional: true` plus Install-Script oder Git-/URL-Quelle.
194
+ - Neue oder stark geänderte transitive Dependencies im PR-Diff.
195
+ - Lockfile fehlt bei Application-/CI-Projekten.
196
+
197
+ Für pnpm/yarn-Lockfiles statisch nach `requiresBuild: true`, Git-/URL-Quellen und nicht erwarteten Registries suchen.
198
+
199
+ ### Phase 5: npm-Tarball-Inhalt prüfen
200
+
201
+ Bei veröffentlichten Paketen ist der Tarball maßgeblich, nicht nur das GitHub-Repo. Prüfe im extrahierten Tarball:
202
+
203
+ - Zusätzliche Dateien: `setup.mjs`, `install.js`, `postinstall.js`, `preinstall.js`, `router_init.js`, große `*.js`-Einzeiler.
204
+ - Unterschiede zwischen Repo und Tarball.
205
+ - Unerwartete `.npmrc`, `.vscode`, `.claude`, `.cursor`, `.devcontainer`, Git-Hooks oder Shell-Scripts.
206
+ - Native Dateien: `.node`, `.so`, `.dll`, `.dylib`, `.exe`, `.wasm`.
207
+ - Große minifizierte/obfuskierte Dateien mit `_0x...`, Base64-Blobs, `crypto.createDecipheriv`, `zlib.gunzipSync`, `eval`, `Function`.
208
+ - `files`-Feld und `.npmignore`: Wird wirklich nur das erwartete Paket ausgeliefert?
209
+
210
+ ### Phase 6: Payload- und Exfiltrationsmuster
211
+
212
+ Suche in TS/JS/MJS/CJS/CLI-Dateien nach Kombinationen:
213
+
214
+ - Netzwerk: `fetch`, `http.request`, `https.get`, `axios`, `got`, `undici`, `curl`, `wget`, URL-Literale.
215
+ - Ausführung: `child_process`, `exec`, `execSync`, `spawn`, `eval`, `new Function`, `vm.runInNewContext`, `WebAssembly.instantiate`.
216
+ - Secrets: `process.env`, `GITHUB_TOKEN`, `NPM_TOKEN`, `NODE_AUTH_TOKEN`, `ACTIONS_ID_TOKEN`, AWS-/Vault-Variablen.
217
+ - Lokale Credential-Dateien: `.npmrc`, `.aws/credentials`, `.config/gh/hosts.yml`, `.git-credentials`, `.netrc`, `.ssh`, `.docker/config.json`.
218
+ - Cloud-/Vault-Probes: `169.254.169.254`, `metadata.google.internal`, `127.0.0.1:8200`.
219
+ - GitHub API Write-Verhalten: `createCommitOnBranch`, `createRef`, `updateRef`, `repos/*/contents`, `api.github.com/graphql`.
220
+ - IDE-/Agent-Pfade: `.claude/settings.json`, `.vscode/tasks.json`, `.cursor`, `.devcontainer`.
221
+
222
+ Eine einzelne Netzwerk- oder Exec-Nutzung kann legitim sein. Die Kombination aus Netzwerk + Ausführung, Secret-Zugriff + Netzwerk oder IDE-Persistence + GitHub Write API ist ein Stop-Signal.
223
+
224
+ ### Phase 7: GitHub Actions und CI/CD
225
+
226
+ Prüfe `.github/workflows/*.yml`:
227
+
228
+ - `pull_request_target` mit Checkout oder `run:` von untrusted Code.
229
+ - `workflow_run` mit Artefakt-Download und Ausführung.
230
+ - `permissions: write-all` oder fehlende Minimalrechte.
231
+ - `contents: write`, `packages: write`, `actions: write`, `id-token: write` ohne klare Begründung.
232
+ - `npm install`/`npm ci` ohne `--ignore-scripts` in Review-/Dependency-Jobs.
233
+ - `npm publish` mit `NPM_TOKEN`/`NODE_AUTH_TOKEN` aus nicht geschützten Branches.
234
+ - Third-party Actions ohne full-length Commit-SHA.
235
+
236
+ ### Phase 8: TypeScript-/Package-Qualität
237
+
238
+ Bewerte:
239
+
240
+ - `tsconfig.json`: `strict`, `noImplicitAny`, `strictNullChecks`, `declaration` für Libraries.
241
+ - `types`/`typings`, `exports`, `main`, `module` zeigen auf vorhandene Dateien.
242
+ - Tests, Linting, Typecheck-Scripts und CI vorhanden.
243
+ - README, LICENSE, SECURITY.md, Repository-Metadaten, `engines.node`.
244
+ - Reproduzierbarkeit: Lockfile für Applications, dokumentierter Build, SBOM, Provenance/Attestations, Release-Tags.
245
+ - Keine unklare generierte Ausgabe in `dist/` ohne nachvollziehbare Quelle.
246
+ - Dependency-Policy: Cooldown für neue Versionen, Renovate/Dependabot mit menschlichem Review, Allowlist für Scripts und non-registry Sources.
247
+
248
+ ## Sichere Installation nach Freigabe
249
+
250
+ Erst nach statischer Prüfung und manueller Freigabe:
251
+
252
+ ```bash
253
+ npm ci --ignore-scripts --omit=optional
254
+ npm audit --audit-level=high
255
+ npm audit signatures
256
+ ```
257
+
258
+ Für Review-Installationen optional zusätzlich moderne npm-Quellbeschränkungen nutzen, falls unterstützt:
259
+
260
+ ```bash
261
+ npm ci --ignore-scripts --omit=optional --allow-git=none --allow-remote=none --allow-file=none
262
+ ```
263
+
264
+ Wenn ein Paket legitime Native Builds oder Install-Scripts braucht, erst eine minimale Allowlist definieren, dann in einer Sandbox ohne Secrets ausführen.
265
+
266
+ ## Natives Pi-Paketmanagement ("pi update")
267
+
268
+ Pi verwaltet Erweiterungen, Skills, Prompt-Templates und Themes nativ über Paket-Definitionen in `~/.pi/agent/settings.json` (unter `"packages"`) unter Verwendung der Protokolle `npm:` und `git:`.
269
+
270
+ - **npm-Pakete (`npm:pkg-name`)**: Werden global (`npm install -g`) oder projektlokal unter `.pi/npm/` installiert.
271
+ - **Git-Pakete (`git:github.com/user/repo`)**: Werden global nach `~/.pi/agent/git/<host>/<path>` geklont. Nach jedem `git pull` führt Pi automatisch `npm install` im geklonten Verzeichnis aus.
272
+
273
+ ### Erstellung des Update-Vorschlags im Report
274
+
275
+ Der Auditor muss am Ende des Berichts **immer** den passenden, maßgeschneiderten Befehl zur Durchführung der sicheren Updates vorschlagen:
276
+
277
+ 1. **Ausschluss-Regel**: Blockierte/quarantänisierte Pakete und zu frische Pakete (`too_fresh`, die die Altersschwelle `min_update_age_hours` unterschritten haben) dürfen **niemals** im Update-Vorschlag enthalten sein.
278
+ 2. **Spezifischer Update-Vorschlag (Chaining)**: Wenn einzelne Pakete aufgrund von Sicherheitsbedenken oder Altersschwellen ausgelassen werden müssen, generiere einen verketteten Einzelupdate-Befehl mittels `&& \`, um nur die verifizierten Pakete gezielt zu aktualisieren:
279
+ ```bash
280
+ pi update npm:pi-mcp-adapter && \
281
+ pi update npm:pi-total-recall && \
282
+ pi update git:github.com/fgladisch/pi-skills
283
+ ```
284
+ 3. **Komplett-Update (Sammelbefehl)**: Wenn alle anstehenden Updates sicher sind und kein Paket ausgelassen werden muss, schlage den Sammelbefehl vor:
285
+ ```bash
286
+ pi update --extensions
287
+ ```
288
+
289
+ ### Interaktive Terminal-Integration (Wrapper)
290
+
291
+ Um den standardmäßigen `pi update` Befehl im Terminal abzufangen, sodass er automatisch diesen interaktiven Sicherheits-Audit triggert und eine interaktive Auswahl anbietet, kann folgende Shell-Funktion in die Shell-Konfiguration (z. B. `~/.zshrc` oder `~/.bashrc`) eingetragen werden:
292
+
293
+ **If installed via GitHub/Git (legacy):**
294
+ ```bash
295
+ pi() {
296
+ if [[ "$1" == "update" && ( -z "$2" || "$2" == "--extensions" ) ]]; then
297
+ python3 ~/.pi/agent/git/github.com/testzugang/pi-plugins/skills/dependency-audit/scripts/pi-interactive-update.py
298
+ else
299
+ command pi "$@"
300
+ fi
301
+ }
302
+ ```
303
+
304
+ **If installed via npm:**
305
+ ```bash
306
+ pi() {
307
+ if [[ "$1" == "update" && ( -z "$2" || "$2" == "--extensions" ) ]]; then
308
+ python3 ~/.pi/packages/node_modules/@testzugang/pi-plugin-dependency-audit/skills/dependency-audit/scripts/pi-interactive-update.py
309
+ else
310
+ command pi "$@"
311
+ fi
312
+ }
313
+ ```
314
+
315
+ Nach dem Neuladen der Shell (`source ~/.zshrc`) führt jede Eingabe von `pi update` oder `pi update --extensions` direkt zu dem interaktiven Audit-Menü.
316
+
317
+ ## Severity-Regeln
318
+
319
+ - `CRITICAL`: bekannte IoC, Credential-Exfiltration, Download+Execute, Secret-Zugriff+Netzwerk, IDE-/Agent-Persistence mit GitHub-Write, Path-Traversal im Tarball, live Token im Paket.
320
+ - `HIGH`: Install-Phase-Lifecycle-Scripts, Git-/URL-/File-Dependencies in `optionalDependencies`, unpinned Git-Dependencies, obfuskierter Lifecycle-Entrypoint, CI mit untrusted Code und Write-/Publish-Rechten.
321
+ - `MEDIUM`: Lockfile-Einträge mit Install-Scripts, non-default Registries, fehlende Integrity, bundled Dependencies, risky Scripts ohne klare Exfil-Kombination, fehlender Lockfile bei Apps.
322
+ - `LOW`: Qualitäts-/Hygieneprobleme, fehlende Metadaten, schwache TS-Konfiguration, fehlende Security-Dateien.
323
+ - `INFO`: Inventar, Workspaces, neutrale Beobachtungen.
324
+
325
+ ## Stop-Regeln
326
+
327
+ Empfehlung sofort auf **nicht nutzen / Quarantäne**, wenn eines zutrifft:
328
+
329
+ - Known IOC im Manifest, Lockfile oder Code.
330
+ - Lifecycle-Script lädt Code/Binaries nach und führt sie aus.
331
+ - Datei kombiniert `child_process`/`eval` mit `fetch`/HTTP/Download.
332
+ - Code liest Tokens oder Credential-Dateien und hat Netzwerk- oder GitHub-API-Zugriff.
333
+ - `optionalDependencies` zeigen auf GitHub/Git/URL und können `prepare` auslösen.
334
+ - npm-Tarball enthält unerwartete IDE-/Agent-Konfigurationen.
335
+ - Workflow kann untrusted Code mit `NPM_TOKEN`, GitHub Write-Rechten oder OIDC ausführen.
336
+
337
+ ## Reportformat
338
+
339
+ Jeder Befund enthält:
340
+
341
+ - Severity.
342
+ - Kategorie.
343
+ - Datei und Zeile.
344
+ - Evidence, kurz und maskiert.
345
+ - Warum riskant.
346
+ - Empfohlene Maßnahme.
347
+ - Status: `confirmed`, `needs-human-review`, `false-positive-candidate`.
348
+
349
+ Nutze `templates/report.md` für manuelle Reviews und die Reports des Scanners für automatisierte Runs.
350
+
351
+ ## Grenzen des Skills
352
+
353
+ Ein sauberer statischer Report beweist nicht, dass ein Paket sicher ist. Er reduziert Früh-Risiko vor Installation und Ausführung. Stark verschleierte Payloads, polymorphe Malware, native Binaries, absichtlich harmlose Stubs mit späterem Remote-Update und Registry-/Account-Kompromisse können zusätzliche manuelle oder sandboxed Analyse erfordern.
@@ -0,0 +1,3 @@
1
+ {
2
+ "min_update_age_hours": 24
3
+ }
@@ -0,0 +1,46 @@
1
+ name: npm TypeScript static package audit
2
+
3
+ on:
4
+ pull_request:
5
+ paths:
6
+ - "package.json"
7
+ - "package-lock.json"
8
+ - "npm-shrinkwrap.json"
9
+ - "pnpm-lock.yaml"
10
+ - "yarn.lock"
11
+ - "src/**"
12
+ - "dist/**"
13
+ - "lib/**"
14
+ - ".github/workflows/**"
15
+ - ".npmrc"
16
+ workflow_dispatch:
17
+
18
+ permissions: {}
19
+
20
+ jobs:
21
+ static-audit:
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ - name: Checkout
25
+ uses: actions/checkout@0000000000000000000000000000000000000000 # Replace with the real full-length commit SHA for actions/checkout
26
+ with:
27
+ persist-credentials: false
28
+
29
+ - name: Run static audit
30
+ run: |
31
+ python3 scripts/npm_ts_static_triage.py . \
32
+ --mode repo \
33
+ --markdown npm-ts-audit.md \
34
+ --json npm-ts-audit.json \
35
+ --sarif npm-ts-audit.sarif \
36
+ --strict-exit
37
+
38
+ - name: Upload audit artifacts
39
+ if: always()
40
+ uses: actions/upload-artifact@0000000000000000000000000000000000000000 # Replace with the real full-length commit SHA for actions/upload-artifact
41
+ with:
42
+ name: npm-ts-audit
43
+ path: |
44
+ npm-ts-audit.md
45
+ npm-ts-audit.json
46
+ npm-ts-audit.sarif
@@ -0,0 +1,110 @@
1
+ # Safe npm/TypeScript audit commands
2
+
3
+ ## 1. Scan a local repository without installing dependencies
4
+
5
+ ```bash
6
+ python3 scripts/npm_ts_static_triage.py /path/to/repo \
7
+ --mode repo \
8
+ --markdown repo-audit.md \
9
+ --json repo-audit.json \
10
+ --sarif repo-audit.sarif \
11
+ --strict-exit
12
+ ```
13
+
14
+ ## 2. Scan a published npm tarball
15
+
16
+ ```bash
17
+ npm view @scope/package@1.2.3 name version dist.tarball dist.integrity dist.shasum time maintainers repository license --json > package-metadata.json
18
+ jq -r '.dist.tarball' package-metadata.json
19
+ curl -fL -o package-under-review.tgz "$(jq -r '.dist.tarball' package-metadata.json)"
20
+ sha256sum package-under-review.tgz
21
+ python3 scripts/npm_ts_static_triage.py package-under-review.tgz --mode package --markdown package-audit.md --json package-audit.json --strict-exit
22
+ ```
23
+
24
+ ## 3. Compare two package tarballs without running npm scripts
25
+
26
+ ```bash
27
+ mkdir -p old new
28
+ python3 - <<'PY'
29
+ import tarfile, pathlib
30
+ for src, dst in [('old.tgz', 'old'), ('new.tgz', 'new')]:
31
+ with tarfile.open(src, 'r:*') as tf:
32
+ tf.extractall(dst, filter='data')
33
+ PY
34
+ diff -ruN old/package new/package > package-diff.patch || true
35
+ ```
36
+
37
+ Review the diff for new `scripts`, `optionalDependencies`, `setup.mjs`, generated JS, hidden config and native binaries.
38
+
39
+ ## 4. Safe review install after static approval
40
+
41
+ ```bash
42
+ npm ci --ignore-scripts --omit=optional
43
+ npm audit --audit-level=high
44
+ npm audit signatures
45
+ ```
46
+
47
+ Only run required lifecycle scripts later in a sandbox without secrets, after the exact package and script have been allowlisted.
48
+
49
+ ## 5. Harden npm defaults for a review environment
50
+
51
+ ```bash
52
+ npm config set ignore-scripts true
53
+ npm config set audit true
54
+ npm config set fund false
55
+ npm config set save-exact true
56
+ npm config set strict-ssl true
57
+ ```
58
+
59
+ If your npm version supports source restrictions, use them for review jobs:
60
+
61
+ ```bash
62
+ npm ci --ignore-scripts --omit=optional --allow-git=none --allow-remote=none --allow-file=none
63
+ ```
64
+
65
+ ## 6. Common manual grep commands
66
+
67
+ ```bash
68
+ grep -RInE 'preinstall|postinstall|prepare|prepack|bundleDependencies|optionalDependencies' package.json package-lock.json pnpm-lock.yaml yarn.lock 2>/dev/null || true
69
+ grep -RInE 'child_process|execSync|spawn\(|eval\(|new Function|fetch\(|https?://|curl|wget|169\.254\.169\.254|GITHUB_TOKEN|NPM_TOKEN|VAULT_TOKEN|\.npmrc|\.aws/credentials|createCommitOnBranch|\.claude|\.vscode/tasks\.json' . --exclude-dir=.git --exclude-dir=node_modules 2>/dev/null || true
70
+ find . -type f \( -name '*.js' -o -name '*.mjs' -o -name '*.cjs' -o -name '*.ts' -o -name '*.tsx' \) -size +500k -print
71
+ ```
72
+
73
+ ## 7. Reusable helpers for global pi dependency checks
74
+
75
+ ```bash
76
+ # current installed versions
77
+ bash scripts/pi-check-current-global-versions.sh
78
+
79
+ # latest npm versions
80
+ bash scripts/pi-check-latest-npm-versions.sh
81
+
82
+ # git-based source updates for local checkouts
83
+ bash scripts/pi-check-git-source-updates.sh
84
+
85
+ # all checks in one call
86
+ bash scripts/pi-check-all-updates.sh
87
+ ```
88
+
89
+ Each helper accepts optional package/repo arguments to override defaults.
90
+
91
+ ## 8. End-to-end global pi update audit (static only)
92
+
93
+ ```bash
94
+ python3 scripts/run_pi_dependency_audit.py --output /tmp/pi_audit_aggregated.json
95
+ python3 scripts/summarize_pi_dependency_audit.py \
96
+ --input /tmp/pi_audit_aggregated.json \
97
+ --output /tmp/pi_audit_report.md
98
+
99
+ # Optional: use custom config (highest precedence)
100
+ python3 scripts/run_pi_dependency_audit.py \
101
+ --config /path/to/dependency-audit.json \
102
+ --output /tmp/pi_audit_aggregated.json
103
+ ```
104
+
105
+ ## 9. Review outcome policy example
106
+
107
+ - CRITICAL: quarantine, do not install, rotate any exposed credentials.
108
+ - HIGH: block until a human reviewer approves a documented fix or allowlist.
109
+ - MEDIUM: review before use; may pass with documented rationale.
110
+ - LOW/INFO: track as hygiene improvements.