* feat(auth): implement ADR-001 Workstream C — ticket auth, SSRF, and pre-flight audit
C1: Boot-time ENCRYPTION_MASTER_KEY / AUTH_SECRET validation (instrumentation.ts);
remove silent fallback in encryption.ts; guard marketplace token from data-plane misuse.
C2: SSRF host-allowlist (PROXY_HOST_ALLOWLIST) in ssrf.ts; route iframe proxy through safeFetch.
C3: ticketClient.ts — exchanges long-lived API key for 5-min EdDSA ticket from Marketplace;
audience fixed to ENGINE_AUDIENCE='wwv-data-engine'; cache keyed by engine not plugin.
C4: WsClient.ts first-message auth — sends {type:'auth',v:1,token} on open; queues subscribes
until {type:'welcome'}; gated by ticketAuthEnabledForPlugin.
C5: edition.ts — ticketAuthEnabledForPlugin reads NEXT_PUBLIC_WWV_TICKET_AUTH_PLUGINS flag.
Step 0: docs/deploys/2026-05-21-adr-001-preflight.md + docs/feature-flags.md audit artifacts.
Tests: ticketClient.spec, WsClient.spec, ssrf.spec updated (342 passing).
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(ci): resolve three PR #171 type-check and startup failures
- auth-contracts.spec.ts: assert WebSocketAuthMessage.token as PluginTicket
(not SensitiveString — distinct branded types fail toEqualTypeOf equality)
- pkce.spec.ts: replace function(){return this} mock with arrow fn to fix
TS2683 implicit-this error in strict mode
- test-local-dev.yml: add ENCRYPTION_MASTER_KEY so instrumentation.ts boot
validation doesn't crash the startup test in CI
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(ci): fix pkce mock constructor and env injection for startup test
- pkce.spec.ts: use function(this: object) instead of arrow fn so the
mock can be called with `new Configuration(...)` (arrow functions are
not constructors)
- test-local-dev.yml: sed-replace ENCRYPTION_MASTER_KEY in .env after
cp .env.example so Next.js instrumentation boot check passes in CI
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(ci): also sed-replace AUTH_SECRET in .env for startup test
.env.example has AUTH_SECRET= (empty), which Next.js loads and overrides
the system env var, causing the same boot crash as ENCRYPTION_MASTER_KEY.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(setup): auto-generate ENCRYPTION_MASTER_KEY in setup.mjs
The Playwright CI workflow uses `pnpm run setup` which previously only
generated AUTH_SECRET. ENCRYPTION_MASTER_KEY remained empty from
.env.example, causing instrumentation.ts boot validation to crash.
This fix also improves the new-developer onboarding experience — both
required secrets are now generated in a single setup step.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
---------
Co-authored-by: Claude Opus 4.7 <[email protected]>
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* @file setup.mjs
|
|
* @description One-command local setup utility.
|
|
* Generates a .env file from .env.example and auto-fills sensitive
|
|
* secrets (like AUTH_SECRET) with secure random values.
|
|
* @module scripts
|
|
*/
|
|
|
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
import { randomBytes } from "crypto";
|
|
import { resolve } from "path";
|
|
|
|
const ROOT = resolve(import.meta.dirname, "..");
|
|
const EXAMPLE = resolve(ROOT, ".env.example");
|
|
const TARGET = resolve(ROOT, ".env");
|
|
|
|
if (existsSync(TARGET)) {
|
|
console.log("✅ .env already exists — skipping setup.");
|
|
console.log(" Delete it and re-run if you want to regenerate.");
|
|
process.exit(0);
|
|
}
|
|
|
|
if (!existsSync(EXAMPLE)) {
|
|
console.error("❌ .env.example not found. Are you in the right directory?");
|
|
process.exit(1);
|
|
}
|
|
|
|
const secret = randomBytes(32).toString("hex");
|
|
const encryptionKey = randomBytes(32).toString("hex");
|
|
let content = readFileSync(EXAMPLE, "utf8");
|
|
|
|
// Fill in the AUTH_SECRET line
|
|
if (content.includes("AUTH_SECRET=")) {
|
|
content = content.replace(/^AUTH_SECRET=.*$/m, `AUTH_SECRET=${secret}`);
|
|
} else {
|
|
content += `\nAUTH_SECRET=${secret}\n`;
|
|
}
|
|
|
|
// Fill in the ENCRYPTION_MASTER_KEY line
|
|
if (content.includes("ENCRYPTION_MASTER_KEY=")) {
|
|
content = content.replace(/^ENCRYPTION_MASTER_KEY=.*$/m, `ENCRYPTION_MASTER_KEY=${encryptionKey}`);
|
|
} else {
|
|
content += `\nENCRYPTION_MASTER_KEY=${encryptionKey}\n`;
|
|
}
|
|
|
|
// Strip comment-only sections (keep values)
|
|
content = content
|
|
.split("\n")
|
|
.map((line) => {
|
|
// Un-comment AUTH_SECRET if it was commented out
|
|
if (line.trim().startsWith("# AUTH_SECRET=")) return line.replace("# ", "");
|
|
return line;
|
|
})
|
|
.join("\n");
|
|
|
|
writeFileSync(TARGET, content, "utf8");
|
|
|
|
console.log("✅ .env created with generated AUTH_SECRET and ENCRYPTION_MASTER_KEY.");
|
|
console.log(" Fill in any optional API keys (Cesium, Bing, OpenSky, etc.)");
|
|
console.log(" then run: npm run dev");
|