changeguard 0.0.0-stage → 0.7.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +440 -0
  2. package/LICENSE +202 -0
  3. package/LICENSE-PROPRIETARY +94 -0
  4. package/README.md +317 -2
  5. package/SECURITY.md +40 -0
  6. package/data/changes/openai.seed.json +87 -0
  7. package/data/changes/shopify.seed.json +42 -0
  8. package/data/changes/stripe.seed.json +60 -0
  9. package/data/changes/supabase.seed.json +56 -0
  10. package/data/changes/twilio.seed.json +63 -0
  11. package/data/openapi/openai/meta.json +9 -0
  12. package/data/openapi/openai/new.json +24 -0
  13. package/data/openapi/openai/old.json +68 -0
  14. package/data/providers/openai.json +60 -0
  15. package/data/providers/shopify.json +52 -0
  16. package/data/providers/stripe.json +57 -0
  17. package/data/providers/supabase.json +56 -0
  18. package/data/providers/twilio.json +57 -0
  19. package/dist/analyze/go-analyzer.js +343 -0
  20. package/dist/analyze/index.js +77 -0
  21. package/dist/analyze/js-analyzer.js +380 -0
  22. package/dist/analyze/parser.js +78 -0
  23. package/dist/analyze/py-analyzer.js +313 -0
  24. package/dist/analyze/rules.js +1 -0
  25. package/dist/analyze/ts-utils.js +62 -0
  26. package/dist/cli.js +335 -0
  27. package/dist/codemod/apply.js +159 -0
  28. package/dist/config.js +121 -0
  29. package/dist/deps/manifests.js +145 -0
  30. package/dist/github/api.js +136 -0
  31. package/dist/github/auth.js +54 -0
  32. package/dist/impact/engine.js +384 -0
  33. package/dist/ingest/canonical.js +52 -0
  34. package/dist/ingest/changelog-html.js +63 -0
  35. package/dist/ingest/feed-client.js +99 -0
  36. package/dist/ingest/feed-keys.js +198 -0
  37. package/dist/ingest/feed.js +178 -0
  38. package/dist/ingest/github-releases.js +59 -0
  39. package/dist/ingest/note-parser.js +274 -0
  40. package/dist/ingest/openapi-diff.js +217 -0
  41. package/dist/ingest/store.js +181 -0
  42. package/dist/llm/explanation.js +273 -0
  43. package/dist/mcp/format.js +116 -0
  44. package/dist/mcp/index.js +29 -0
  45. package/dist/mcp/protocol.js +36 -0
  46. package/dist/mcp/server.js +110 -0
  47. package/dist/mcp/standalone.js +12 -0
  48. package/dist/mcp/tools.js +189 -0
  49. package/dist/notify/index.js +174 -0
  50. package/dist/providers/registry.js +215 -0
  51. package/dist/report/html.js +194 -0
  52. package/dist/report/markdown.js +90 -0
  53. package/dist/report/pr-draft.js +37 -0
  54. package/dist/scan.js +168 -0
  55. package/dist/source/repo-source.js +100 -0
  56. package/dist/types.js +6 -0
  57. package/dist/util/http.js +40 -0
  58. package/dist/util/logger.js +61 -0
  59. package/dist/util/metrics.js +99 -0
  60. package/dist/util/request-context.js +22 -0
  61. package/dist/util/task-queue.js +69 -0
  62. package/dist/util/versions.js +52 -0
  63. package/fixtures/sample-repo/cmd/billing/main.go +47 -0
  64. package/fixtures/sample-repo/go.mod +12 -0
  65. package/fixtures/sample-repo/package.json +17 -0
  66. package/fixtures/sample-repo/requirements.txt +7 -0
  67. package/fixtures/sample-repo/services/ai.py +65 -0
  68. package/fixtures/sample-repo/src/billing.ts +68 -0
  69. package/package.json +84 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,440 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here.
4
+
5
+ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ Nothing yet.
11
+
12
+ ## [0.7.0] - 2026-11-19
13
+
14
+ ### Added
15
+
16
+ - MCP server (`changeguard mcp` / `changeguard-mcp` bin): the deterministic
17
+ scan engine is now reachable by agents over stdio JSON-RPC. Three read-only
18
+ tools — `list_breaking_changes`, `check_impact` (file:line impact with rule
19
+ ids), `get_feed_status` (explicit provenance for citation) — with
20
+ agent-friendly Markdown output, zero dependencies, and zero kernel changes
21
+ (`persist:false`, `online:false`). Safety is structural: absolute-path
22
+ validation with an optional `CHANGEGUARD_MCP_ALLOWED_ROOTS` allow-list, 30s
23
+ scan timeout, stdout carries protocol frames only (diagnostics on stderr),
24
+ BOM-tolerant framing. Implemented as the legacy handshake era
25
+ (2025-06-18): every current mainstream client probes `server/discover` then
26
+ falls back to `initialize`, so it is reachable everywhere; the 2026-07-28
27
+ stateless era is a follow-up. Publish gate now hard-fails when the tarball
28
+ omits `dist/mcp/*` (the local-works / packaged-missing class of bug).
29
+ `docs/mcp.md` documents the tool contracts, three client configs and the
30
+ read-only/offline guarantees. 15 MCP tests (protocol + tools + e2e).
31
+
32
+ Nothing yet.
33
+
34
+ ## [0.6.1] - 2026-11-17
35
+
36
+ ### Added
37
+
38
+ - Performance baseline in README (measured on synthetic repos, dist form):
39
+ 100 files/200 call sites in 0.75s, 500/1000 in 0.84s, 2000/4000 in 1.99s —
40
+ marginal cost ≈0.65ms/file. Reproducible via `scripts/gen-synth-repo.ts`
41
+ (mixed TS/Py/Go generator mimicking the fixture call shapes).
42
+ - `docs/maintenance.md`: ten-minute takeover checklist, the eight-step
43
+ release procedure, an index of every real pitfall hit during development,
44
+ an architecture map, backlog and handover notes. The project is declared
45
+ in **maintenance mode** at v0.6.0: bug and security fixes only, new
46
+ features require real user demand.
47
+
48
+ ### Fixed
49
+
50
+ - `changeguard --version` reports the real package version. It had been
51
+ hard-coded as `0.1.0` for five releases (0.2.0–0.6.0 all claimed 0.1.0),
52
+ caught by installing the 0.6.0 tarball into a clean prefix. The version now
53
+ resolves from package.json (from src/ and dist/ alike), with a regression
54
+ test that runs the CLI and compares against package.json.
55
+
56
+ ## [0.6.0] - 2026-11-16
57
+
58
+ ### Added
59
+
60
+ - Audit-log retention: `purgeAuditLogs(retentionDays)` plus scheduler wiring
61
+ (`CHANGEGUARD_AUDIT_RETENTION_DAYS`, default 90, 0 disables). Runs once at
62
+ boot and every 24h, independently of scan scheduling. The data-policy page
63
+ now states 90-day rotation instead of "kept until deletion".
64
+ - Self-service tenant deletion: `DELETE /api/tenant` (owner session or the
65
+ local no-password mode; exact-tenant-name confirmation required; API keys
66
+ refused with 403) backed by a single-transaction `deleteTenantData` that
67
+ removes scans/reports, API keys, installations, audit rows, memberships,
68
+ settings and the tenant row, returning per-table counts. The console
69
+ Settings page gained a SEC-04 danger-zone panel. Verified end-to-end in
70
+ local mode; 6 new tests, 187 total.
71
+
72
+ ### Changed
73
+
74
+ - R3 parameter findings skip feature-kind changes. A feature note ("new
75
+ parameter available") is an update-log entry, not a risk signal; R9
76
+ already excluded feature changes for the same reason. Measured effect: the
77
+ 18 LOW findings in an online `--only-matched` view drop to zero (26
78
+ findings → 8; HIGH 3 / MEDIUM 5 / LOW 0). The offline baseline reading
79
+ 45 → 44 for the same release is the correct consequence of R9 aggregation
80
+ (a same-provider medium+low pair merged into one medium: 35+9+1 →
81
+ 35+9+0), not a regression — no test pins the total.
82
+ - Title fallback also rejects generic section headers (`Breaking changes`,
83
+ `Change type`, `Changelog`, `Release notes`, `What's changed` …) and keeps
84
+ scanning the entry body for a substantive line. Also documented: the
85
+ ingest layer caches **parsed** records for 6h, so parser changes require
86
+ clearing `.changeguard/cache` before re-verification (the first re-run
87
+ looked unchanged for exactly this reason).
88
+
89
+ ### Added
90
+
91
+ - `changeguard scan --only-matched`: keep only findings anchored to a
92
+ concrete file (call-site hits). Repo-level advisories (R9) and
93
+ dependency-level pins (R7) drop out of this view; filtering happens before
94
+ every count so summary and artifacts stay consistent. Verified online:
95
+ 26 findings → 19, all file-anchored, HIGH 3 → 1 (the two R7 pins correctly
96
+ excluded).
97
+
98
+ ### Fixed
99
+
100
+ - Release-note titles: entries headed by a version tag (`### v7.44.0`),
101
+ a date-style name (`2026-08-25`, `2026-09-30.endive`) or punctuation
102
+ (`### -`) now fall back to the first substantive body line, so reports no
103
+ longer show findings titled "v7.44.0". Meaningful headings stay untouched,
104
+ output is clamped to 140 chars, and slug/id generation follows the fixed
105
+ title. Verified against a live online scan: advisory titles now carry the
106
+ actual change text ("Make id, sessionId and sessionToken required…").
107
+
108
+ ### Changed
109
+
110
+ - R9 repo advisories are now aggregated per provider instead of one finding
111
+ per un-matched change. Measured on a real online scan: 59 findings → 8
112
+ (86% fewer), with the three genuinely matched HIGH findings no longer
113
+ buried under 45 per-change "may affect this repository" entries. Each
114
+ advisory keeps the information: un-matched count, kind breakdown
115
+ (breaking / deprecation / behavior), the three latest titles, and a
116
+ "+N more" tail. Severity logic is unchanged — a group containing any
117
+ un-matched breaking change stays `medium`, deprecation/behavior-only
118
+ groups are `low`. The representative change (newest breaking, else newest)
119
+ still drives the report's change detail.
120
+
121
+ ### Added
122
+
123
+ - `scripts/backup-to.ps1` + `docs/backup.md`: one-command bundle backup to
124
+ removable media (`-AutoUsb` finds the USB drive, creates the bundle,
125
+ copies, verifies with `git bundle verify`, keeps the newest 3) plus a
126
+ documented restore drill (clone from bundle → npm ci → test). The script
127
+ is pure ASCII on purpose — Windows PowerShell 5.1 parses BOM-less UTF-8
128
+ as ANSI and breaks the parser otherwise.
129
+ - `SECURITY.md` with a vulnerability disclosure process (3-day ack, 7-day
130
+ triage, 30/90-day fix windows), in/out of scope, and the fail-closed
131
+ design notes reviewers need. The privacy policy already cited it — now
132
+ the file exists.
133
+
134
+ ### Changed
135
+
136
+ - CI now enforces the linters that were configured but never wired up: every
137
+ push and PR runs `npm run lint` (ESLint flat config) and
138
+ `npm run format:check`. `npm run check:fast` (typecheck + lint +
139
+ format:check) and `npm run check` (+ tests) reproduce the same gate locally
140
+ before pushing.
141
+ - `format` and `format:check` now pass an explicit path (`.`). Prettier 3
142
+ rejects a path-less invocation (`No parser and no file path given`), so the
143
+ check had been failing on its own arguments instead of validating the repo.
144
+ - `.prettierignore` also covers `.changeguard/`, `coverage/` and `backups/`:
145
+ runtime artifacts and generated reports are not repository sources, and
146
+ scanning them would make the check depend on whatever was last generated.
147
+
148
+ ### Fixed
149
+
150
+ - Prettier violations in `docker-compose.yml`, `docker-compose.multi.yml` and
151
+ `tests/node-sqlite-shim.mjs` (formatting only, no behavior change).
152
+
153
+ ## [0.5.0] - 2026-11-14
154
+
155
+ ### Added
156
+
157
+ - `docs/stripe-sandbox.md` — Stripe test-mode onboarding & verification
158
+ checklist (7 items, each mapped to the implementing code; notes that
159
+ `config.stripe.enabled` depends on the webhook secret alone).
160
+ - `docs/trial-playbook.md` — the 3–5 real-user trial script that turns the
161
+ CRL evidence gap into first-hand data: target personas, 30-minute script,
162
+ a 5-question feedback form (false-positive rate, novel findings,
163
+ forwarding intent, price anchor) and a mandatory feedback-log template.
164
+ - Legal pages: `/privacy`, `/terms`, `/data-policy` — public (whitelisted in
165
+ UNPROTECTED, served on a locked console), reachable from the login page and
166
+ the pricing footer. Content is grounded in the actual storage schema
167
+ (users/memberships/scans/reports/audit_log/api_keys + stateless HMAC
168
+ sessions): API keys stored hashed, report payloads carry code snippets,
169
+ LLM is disclosed as an optional third-party processor, self-service scan
170
+ deletion documented (`DELETE /api/scans/:id`), account/tenant deletion via
171
+ the contact mailbox in 30 days, plus an explicit "draft, not legal advice"
172
+ notice. A locked-console test proves whitelisting (legal pages 200 while
173
+ other paths 303-redirect). 6 new tests; 174 total.
174
+
175
+ ### Added
176
+
177
+ - `npm run feed:refresh` — seed refresh tool (`scripts/refresh-seeds.ts`).
178
+ Pulls release notes for every provider SDK repo (default since
179
+ 2025-01-01), filters to actionable kinds (breaking / deprecation /
180
+ behavior), deduplicates cross-language SDK duplicates (version banner
181
+ normalized), and separates records that carry **match anchors**
182
+ (non-empty `operations[].sdkPaths` or `renames`) from metadata-only
183
+ records. `--apply` appends only anchored, id-new records to
184
+ `data/changes/<provider>.seed.json`; anchors are never guessed — records
185
+ without one are reported for manual API-surface annotation. Dry run by
186
+ default. Observed on 2026-11-14: 87 actionable records -> ~80 unique,
187
+ only a handful anchored (note-parser extracts sdkPaths from explicit
188
+ field-level release text); the rest need human annotation. Anonymous
189
+ GitHub API allows 60 requests/hour — set `GITHUB_TOKEN` for a full run.
190
+
191
+ ### Added
192
+
193
+ - Structured logging. `CHANGEGUARD_LOG_FORMAT=json` switches the logger to
194
+ one JSON object per line (`t`, `level`, `msg`); the human format stays the
195
+ default. Every HTTP request runs inside an AsyncLocalStorage context, so
196
+ all 47 existing logger call sites automatically carry `requestId` (plus
197
+ `tenantId`/`actor` once auth resolves, and `method`/`path`) with zero
198
+ signature changes — async continuations and scans enqueued from a request
199
+ keep the context. The server mints a UUID per request (or honors an
200
+ inbound `X-Request-Id` from a proxy) and echoes it in the `X-Request-Id`
201
+ response header. JSON mode also emits one access line per request
202
+ (`access GET /path 200`), skipping `/healthz`, `/favicon.ico` and
203
+ `/metrics`. 8 new tests; 168 total.
204
+
205
+ ### Added
206
+
207
+ - Data-driven provider registry. Each vendor is now a JSON manifest in
208
+ `data/providers/<id>.json` (file stem must equal the id), loaded and
209
+ strictly validated at startup by `loadProviderManifests()` /
210
+ `validateProviderManifest()`. Adding a vendor is a data change with zero
211
+ code edits: package/host matching, three-language analyzer rules and
212
+ online change sources all derive from the manifest. Validation is
213
+ fail-fast and names the offending file and field (unknown
214
+ ecosystem/language, malformed `githubReleases`, stem/id mismatch, invalid
215
+ JSON, empty directory). `providerForPackage` / `providerForHost` /
216
+ `buildAnalyzerIndex` accept an injectable provider list for tests and
217
+ custom deployments. The five built-ins migrate to manifests with behavior
218
+ unchanged (pinned by `tests/providers.test.ts`, 16 new cases).
219
+
220
+ ## [0.4.0] - 2026-11-13
221
+
222
+ ### Fixed
223
+
224
+ - `GET /favicon.ico` now answers 204 instead of 404, keeping the browser
225
+ console clean (the real favicon lives with the out-of-repo marketing site).
226
+ - The login terminal header shows the server version from package.json
227
+ (it was hard-coded as v0.2 and already stale).
228
+
229
+ ### Changed
230
+
231
+ - Design docs reality check: the blueprint (`docs/design-plan.md`) drifted
232
+ behind the code after P2 — the server-rendered pages (dashboard / pricing /
233
+ auth) moved from the phosphor-green v1 tokens to the purple Sonar tokens,
234
+ and the pricing page had already been unified into the v2 language (SEC
235
+ section numbering, intercept-log style tier rows, STANDING BY stamp). The
236
+ blueprint now carries a §8 evolution record marking the drift, and P5's
237
+ "inline monospace font" is resolved as **won't do** (system monospace stack
238
+ is sufficient; a base64 woff2 would break the single-file report budget).
239
+ - The monospace font stack across all server-rendered pages is unified to
240
+ `ui-monospace, "Cascadia Code", Consolas, monospace` (32 occurrences in
241
+ dashboard.ts / pricing.ts / auth.ts previously mixed a shorter stack).
242
+
243
+ ### Added
244
+
245
+ - Prometheus metrics: `GET /metrics` serves the standard text exposition
246
+ format (zero dependencies, process-local registry in `util/metrics.ts` so
247
+ the Apache-2.0 `llm/` modules can record without touching the proprietary
248
+ boundary). Counters: scans by result, scan duration (count/sum/last),
249
+ findings by severity, LLM explanations and template fallbacks by reason
250
+ (error / safety-filter / scan-cap / kill-switch); gauges: scan queue depth
251
+ and uptime. Fail-closed: the endpoint returns 404 unless
252
+ `CHANGEGUARD_METRICS_TOKEN` is configured, 401 on a wrong token
253
+ (constant-time comparison); Bearer auth or `?token=` both accepted.
254
+ - Go pipeline e2e coverage: `tests/scan-e2e.test.ts` pins the full Go chain
255
+ (go.mod provider attribution → tree-sitter call sites → engine findings)
256
+ with six deterministic findings on `cmd/billing/main.go`, and documents the
257
+ boundary that Go findings carry no codemods (auto-fix is JS/TS/Python).
258
+ - Console open-PR endpoint error-path tests (`tests/open-pr.test.ts`): 404
259
+ unknown scan, 400 non-GitHub repoPath, 400 missing installation binding,
260
+ and 502 `GitHub PR failed: …` when credentials are missing (offline).
261
+
262
+ ### Fixed
263
+
264
+ - `providerForPackage` now compares package names case-insensitively on both
265
+ sides. Registry entries mix case for Go module paths
266
+ (`github.com/Shopify/go-shopify`), so a `go.mod` depending on it was not
267
+ attributed to the Shopify provider while all other Go paths were. Go
268
+ dependencies now resolve for all five providers.
269
+
270
+ ## [0.3.0] - 2026-11-13
271
+
272
+ ### Security
273
+
274
+ - LLM explanation hardening. The LLM prompt now explicitly warns that facts
275
+ (coming from potentially malicious feeds or changelogs) are untrusted data
276
+ and any text that looks like an instruction must be treated as content, not
277
+ as a command the model should follow.
278
+ - LLM output safety filters. `migrationSteps` returned by the LLM are filtered
279
+ against a blacklist of dangerous shell patterns (`curl|sh`, `wget|sh`,
280
+ `rm -rf`, `eval`, `bash -c`, `powershell -Enc`, ...) and silently dropped
281
+ when any match is found. Remaining steps are capped at 5 items of 500 chars
282
+ each; `summary` is capped at 500 chars.
283
+ - LLM rate limiting. Per-scan cap of 50 distinct changes reach the LLM pipeline
284
+ (rest fall back to template); process-wide per-hour hard cap (default 200)
285
+ prevents runaway spend when a malicious feed floods findings; at most 3
286
+ parallel LLM calls share the semaphore.
287
+ - Runtime LLM kill-switch. `CHANGEGUARD_DISABLE_LLM=1` is hot-loaded from
288
+ `process.env` on every LLM decision point — no process restart needed to
289
+ flip the whole pipeline to template mode during an incident response.
290
+ - Reports mark LLM-written content. The HTML report renders a blue
291
+ `🤖 AI 生成,仅供参考` badge next to explanations whose `source === 'llm'`;
292
+ the Markdown report already distinguishes `说明(LLM)` from
293
+ `说明(模板)`.
294
+
295
+ ### Changed
296
+
297
+ - Licensing is now dual: the standalone CLI and scanner are Apache-2.0
298
+ (`LICENSE`), while the hosted server, tenant/billing storage, console and
299
+ deployment packaging remain proprietary (`LICENSE-PROPRIETARY`, which also
300
+ defines the path-level boundary and the rules for mixed directories).
301
+ `package.json` declares `"license": "Apache-2.0"`.
302
+ - The CLI is split at the license boundary: `serve`, `tenant`, `key`, `plan`,
303
+ `audit` and `bind-installation` moved to the proprietary `src/cli-admin.ts`.
304
+ `src/cli.ts` now contains no import of `src/server/**` or `src/store/**` and
305
+ registers unavailable stubs with the same command names when the extension
306
+ is absent (Apache-2.0-only distribution). Command names, arguments, output
307
+ and exit codes are unchanged when the extension is present.
308
+ - The npm package is constrained by a `files` allowlist in `package.json`: it
309
+ ships only the Apache-2.0 portion, so `dist/server/**`, `dist/store/**`,
310
+ `dist/cli-admin.*` and the Docker files never enter the tarball.
311
+
312
+ ### Added
313
+
314
+ - Signed change feeds (feed v1): an ed25519-signed JSON envelope
315
+ (`{feedVersion, publisher, generatedAt, records, signature}`) verified with
316
+ Node's built-in `crypto` (no new dependencies). Signatures cover the
317
+ canonical JSON of everything except `signature`, so later publishers can add
318
+ fields without breaking older clients. `scan`, `pr-preview` and `pr-open`
319
+ accept `--feed <path|url>` and `--trusted-keys <file>`; verification is
320
+ fail-closed (missing signature, unknown `kid`, retired key, tampered payload
321
+ all reject the feed). See `docs/feed.md`.
322
+ - Two-layer feed trust: long-lived root keys built into the package
323
+ (`BUILTIN_ROOT_KEYS`, several allowed for root rotation) sign a keyring
324
+ (`{keyringVersion, generatedAt?, keys[], signature}`), and only after that
325
+ root signature verifies are the signing keys listed in the keyring
326
+ (`kid`, public key, optional `notBefore` / `retiresAt`) trusted for feeds.
327
+ Signing-key rotation therefore only re-signs a keyring — already-installed
328
+ CLIs accept it without a release; root rotation ships a CLI release that
329
+ trusts both roots during the overlap. Keyrings may be fetched over
330
+ `http(s)` because the root signature is checked locally.
331
+ `CHANGEGUARD_FEED_KEYS` / `CHANGEGUARD_FEED_ROOT_KEYS` select a keyring and
332
+ extra roots by environment. `BUILTIN_ROOT_KEYS` and `BUILTIN_FEED_KEYRING`
333
+ now carry bootstrap keys (root public key + signed keyring generated
334
+ 2026-11-13, private keys stay outside the repository); re-run the key
335
+ ceremony in an isolated environment and rotate before serving external
336
+ users (see `docs/feed.md` for the checklist).
337
+ - Strict feed mode: `CHANGEGUARD_FEED_STRICT=1` turns any verification failure
338
+ (including keyring rejections) into a non-zero exit with no fallback; the
339
+ default stays "error + warn + fall back to the bundled snapshot, exit 0".
340
+ CI pipelines must enable it, otherwise a failure silently degrades to stale
341
+ data.
342
+ - New rejection reasons: `keyring-malformed`, `keyring-unsigned`,
343
+ `keyring-unknown-root`, `keyring-bad-signature`, and `not-yet-valid` for
344
+ keys before their `notBefore` (retirement keeps using `retired-key`;
345
+ `keyring` covers unreadable root files and a missing keyring).
346
+ - `scripts/feed-keyring.ts` (npm `feed:keyring`) signs a keyring with a root
347
+ key and self-checks it against the root public key.
348
+ - `scripts/feed-keygen.ts` generates an ed25519 key pair into a git-ignored
349
+ `.keys/` directory (private key mode 0600; refuses paths inside the
350
+ repository that git does not ignore). `scripts/feed-sign.ts` signs the
351
+ bundled snapshot or an explicit `--records` file. npm scripts
352
+ `feed:keygen` / `feed:sign` wrap both.
353
+ - `tests/feed.test.ts` covers canonical serialization stability, sign→verify,
354
+ tampered payload, missing signature, unknown `kid`, unsupported version,
355
+ keyring root-signature acceptance/rejection (tampered bytes, unknown root,
356
+ unsigned, unsupported version), signing-key rotation with `notBefore` /
357
+ `retiresAt`, and keyring `kid`/key mismatch.
358
+ - `tests/cli-admin.test.ts` pinning the proprietary admin command surface
359
+ (tenant / key / audit subcommands).
360
+ - `tests/license-boundary.test.ts` guards the Apache-2.0 boundary: no
361
+ `server`/`store` imports in `src/cli.ts` (comments excluded) and no
362
+ proprietary path can match the `files` allowlist in `package.json`. It also
363
+ asserts the CLI resources (dist, `data/`, `fixtures/`, both license files)
364
+ are still shipped. The check is static, so it needs no network.
365
+
366
+ ### Fixed
367
+
368
+ - The CLI now exits 1 cleanly instead of crashing with 0xC0000409 on Windows
369
+ with Node >= 24 when a command fails while tree-sitter WASM / SQLite handles
370
+ are still closing: the synchronous `process.exit(1)` in the top-level catch
371
+ tripped a libuv assertion (`src/win/async.c`). Affected paths include
372
+ `CHANGEGUARD_FEED_STRICT=1` rejecting a feed. The failure exit is now
373
+ `process.exitCode` plus a natural drain, with a bounded unref'd timer as
374
+ fallback.
375
+ - Scans no longer warn `failed to persist scan … Cannot find module` in the
376
+ Apache-2.0-only build. A missing `store/sqlite` module is treated as
377
+ "persistence not available" and skipped silently; real write failures are
378
+ still reported.
379
+
380
+ ## [0.2.0] - 2026-11-07
381
+
382
+ ### Changed
383
+
384
+ - **Security: fail-closed defaults.** The console and JSON API now require
385
+ authentication by default; when neither `CHANGEGUARD_CONSOLE_PASSWORD` nor
386
+ GitHub OAuth is configured the console returns 503 with setup instructions
387
+ instead of serving the implicit local tenant. Local development opts out
388
+ explicitly with `CHANGEGUARD_ALLOW_ANONYMOUS_CONSOLE=1`.
389
+ - `POST /webhook` now rejects payloads that cannot be verified when
390
+ `GITHUB_WEBHOOK_SECRET` is unset (previously accepted). Dev opt-in:
391
+ `CHANGEGUARD_ALLOW_UNSIGNED_WEBHOOK=1`.
392
+ - Session cookies no longer fall back to a hard-coded secret. An unset
393
+ `CHANGEGUARD_SESSION_SECRET` generates a random per-process secret, so
394
+ sessions end on restart; set the variable in production.
395
+
396
+ ### Added
397
+
398
+ - Login rate limiting: 10 attempts per client IP per 15 minutes, then 429 with
399
+ `Retry-After`.
400
+ - `Secure` session cookies when the request arrives over TLS (or via a trusted
401
+ proxy's `X-Forwarded-Proto`), plus `CHANGEGUARD_SECURE_COOKIES` to force it.
402
+ - Baseline security response headers: CSP, `X-Content-Type-Options`,
403
+ `X-Frame-Options`, `Referrer-Policy`, `Permissions-Policy`, and HSTS over TLS.
404
+ - `CHANGEGUARD_TRUST_PROXY` for reverse-proxy deployments (per-client rate
405
+ limiting and `Secure` cookies).
406
+ - `tests/security.test.ts` covering fail-closed defaults, signature
407
+ verification, session secret, rate limiting and cookie attributes.
408
+
409
+ ## [0.1.0] - 2026-11-07
410
+
411
+ First tagged baseline. Everything below is the state of the repository at this tag.
412
+
413
+ ### Added
414
+
415
+ - Deterministic scanning engine: 9 rules (R1-R9) over 5 providers (Stripe, OpenAI,
416
+ Shopify, Twilio, Supabase) across JavaScript/TypeScript, Python and Go.
417
+ - Tree-sitter (WASM) based parsing with zero native build dependencies.
418
+ - Artifacts per scan: `report.json`, `report.md`, `report.html`, `pr-body.md`,
419
+ `codemod.patch`.
420
+ - CLI: `scan`, `demo`, `serve`, `pr-open <owner/repo>`, `github pr`.
421
+ - Multi-tenant control plane: tenants, hashed API keys, HMAC session cookies,
422
+ GitHub OAuth SSO, Stripe Checkout and webhook plan sync, quota gating (HTTP 402),
423
+ audit log, usage export (CSV/JSON), `/pricing` page.
424
+ - Plan limits: free (2 repos / 10 scans), pro (25 repos / 500 scans), team
425
+ (100 repos / 5000 scans).
426
+ - Notification channels: GitHub Issue (deduplicated by findings hash), draft
427
+ pull request, Slack webhook, SMTP email.
428
+ - GitHub App webhook receiver (`installation`, `installation_repositories`, `push`) with
429
+ HMAC-SHA256 signature verification.
430
+ - Scheduler for periodic re-scans, plus a bounded task queue.
431
+ - Console: scan history with per-scan Issue / PR links, repo management, API key
432
+ management, and the two HTML manuals with full-text search.
433
+ - Docker support: `Dockerfile` (node:22-bookworm-slim) and single- / multi-instance
434
+ `docker-compose` files.
435
+
436
+ ### Known gaps
437
+
438
+ - No signed change feed: seeds are hand-maintained and untrusted-by-default.
439
+ - SQLite is single-writer, so the multi-instance compose file is only safe with
440
+ the app-ro replica read-only.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.