Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Auto-provision Playwright MCP + close reviewer Part B security gaps

Jeromea31ee0e91b37
diff --git a/.claude/agents/quality-reviewer.md b/.claude/agents/quality-reviewer.md
index e70e33e4..70d75115 100644
--- a/.claude/agents/quality-reviewer.md
+++ b/.claude/agents/quality-reviewer.md
@@ -353,6 +353,17 @@ Supabase-specific:
- Only relevant if `package.json` / lockfile changed
- Then: `npm audit --audit-level=high` returns no HIGH/CRITICAL
+### B.8 Crypto, file paths & untrusted parsing (WARNING; HIGH when user-facing)
+Closes the gap vs a generic `/security-review` pass: B.1-B.7 are Supabase-tuned, these are the
+category-level checks a generic pass adds. Same bar as B (realistic attack vector only).
+- **Crypto/randomness**: no weak hash for secrets (MD5/SHA1); no `Math.random()` for tokens, IDs,
+ or keys (use `crypto`); hardcoded IV/salt/key = CRITICAL (see B.2).
+- **Path traversal**: a Supabase Storage key or filesystem path is derived server-side from a
+ trusted id, never from a raw client filename that can carry `../` or an absolute path (attachments).
+- **Untrusted parsing** (CSV import, inbound-email webhook, uploads): size/shape validated before
+ processing; a malformed row fails that row, not the batch; CSV *export* neutralizes formula
+ injection (a cell starting with `= + - @` is prefixed) so an exported contact can't run in Excel.
+
---
## Part C — QA / runtime validation
diff --git a/.claude/hooks/ensure-playwright-mcp.mjs b/.claude/hooks/ensure-playwright-mcp.mjs
new file mode 100644
index 00000000..0126cac4
--- /dev/null
+++ b/.claude/hooks/ensure-playwright-mcp.mjs
@@ -0,0 +1,97 @@
+#!/usr/bin/env node
+// SessionStart: ensure the Playwright MCP browser is provisioned so the harness
+// feature-smoke (quality-reviewer MODE: feature-smoke) can DRIVE the app itself.
+//
+// The server is already wired: .mcp.json declares it (node
+// node_modules/@playwright/mcp/cli.js) and the developer / quality-reviewer agents
+// carry the mcp__playwright__browser_* tools. The only failure mode seen in the wild
+// is a partial `npm install` that never pulled `@playwright/mcp` (or its chromium),
+// which silently degrades feature-smoke to static checks. This hook detects that and
+// auto-repairs it, so the demo-smoke works without a human running `make install`.
+//
+// An MCP server connects at SESSION START, before any hook finishes, so a synchronous
+// install here could NOT connect the server for THIS session anyway. The right move is
+// therefore: detect fast, kick off `make install-playwright-browsers` DETACHED in the
+// background (logged), and warn that feature-smoke degrades this session and will work
+// the next one. Fast when present (the 99% case), never blocks startup, never throws.
+
+import { existsSync, statSync } from "node:fs";
+import { readFileSync } from "node:fs";
+import { spawn } from "node:child_process";
+import { join } from "node:path";
+import { createHookContext } from "./lib/context.mjs";
+
+let input = {};
+try {
+ input = JSON.parse(readFileSync(0, "utf8"));
+} catch {
+ process.exit(0); // no payload -> nothing to do
+}
+const ctx = createHookContext(input, "ensure-playwright-mcp");
+
+const repo = process.env.CLAUDE_PROJECT_DIR || process.cwd();
+const mcpCli = join(repo, "node_modules", "@playwright", "mcp", "cli.js");
+
+// Present -> nothing to do. Fast path, no output (avoid per-session noise).
+if (existsSync(mcpCli)) {
+ ctx.log("playwright MCP present");
+ process.exit(0);
+}
+
+// A global lock so parallel sessions don't launch duplicate installs. A fresh lock
+// (< 30 min) means an install is already running; just warn, don't relaunch.
+const lock = "/tmp/atomic-crm-playwright-mcp-install.lock";
+let installing = false;
+try {
+ if (
+ existsSync(lock) &&
+ Date.now() - statSync(lock).mtimeMs < 30 * 60 * 1000
+ ) {
+ installing = true;
+ }
+} catch {
+ // ignore -> treat as not installing
+}
+
+const installLog = join(ctx.sessionDir, "playwright-mcp-install.log");
+
+if (!installing && process.env.PLAYWRIGHT_MCP_CHECK_ONLY !== "1") {
+ try {
+ // Detached: returns immediately, survives this hook's exit. `make
+ // install-playwright-browsers` runs `npm install` then `npx playwright install
+ // chromium chromium-headless-shell`; provisions both the MCP package and browsers.
+ const cmd = `touch "${lock}"; make -C "${repo}" install-playwright-browsers > "${installLog}" 2>&1; rm -f "${lock}"`;
+ const child = spawn("bash", ["-lc", cmd], {
+ detached: true,
+ stdio: "ignore",
+ });
+ child.unref();
+ ctx.log(
+ `playwright MCP missing -> background install started, log=${installLog}`,
+ );
+ } catch (e) {
+ ctx.log(
+ `playwright MCP missing -> could not start install: ${e?.message ?? e}`,
+ );
+ }
+} else {
+ ctx.log("playwright MCP missing -> install already in progress");
+}
+
+// Warn the session: the MCP cannot connect mid-session, so feature-smoke degrades to
+// static checks THIS run; it will drive the browser once the install completes.
+process.stdout.write(
+ JSON.stringify({
+ hookSpecificOutput: {
+ hookEventName: "SessionStart",
+ additionalContext:
+ `<playwright-mcp-status>NOT INSTALLED. The Playwright MCP browser is being ` +
+ `provisioned in the background (log: ${installLog}). For THIS session the harness ` +
+ `feature-smoke (MODE: feature-smoke) cannot drive the UI and will fall back to ` +
+ `static/compile checks; the Supabase e2e-smoke (CLI Playwright) is unaffected. It ` +
+ `will be available next session. To provision now: run \`make install-playwright-browsers\`.` +
+ `</playwright-mcp-status>`,
+ },
+ }) + "\n",
+);
+process.exit(0);
diff --git a/.claude/settings.json b/.claude/settings.json
index 274b68a4..2f62fd22 100644
--- a/.claude/settings.json
+++ b/.claude/settings.json
@@ -32,6 +32,11 @@
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-bootstrap.mjs",
"timeout": 10
+ },
+ {
+ "type": "command",
+ "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/ensure-playwright-mcp.mjs",
+ "timeout": 10
}
]
}
diff --git a/CLAUDE.md b/CLAUDE.md
index 2a8129c3..5671ae95 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -33,7 +33,7 @@ Off by default. `#harness` (or "use the agent team" / "with the harness") routes
orchestrator (routes the harness, dispatched by the main thread), planner, developer, quality-reviewer, merger, documentator. Models/roles: see each `.claude/agents/*.md`; **planner** and **quality-reviewer** run on opus, everything else on sonnet or haiku. (The web-chat variant is this same `orchestrator` with a non-technical persona layered on at launch via `--append-system-prompt`, used by CRM Builder.)
-The **developer** is a single agent with no modes: it implements the ticket in `TICKET_FILE` (COMPLEX wave, peer-reviewed, writes ADRs for structural decisions, never writes SQL during tickets), or for a SIMPLE dispatch the change described inline via `CHANGE_REQUEST` (no ticket, no planner, on the shared `<base>/simple` worktree; it refuses with `FAILED: out of scope, needs COMPLEX flow` if the change needs a breakdown). Two session-level operations reach it as **skills** loaded on dispatch, run on the same `<base>/simple` worktree: `writing-migrations` (deploy-time SQL generation) and `resolving-rollback-conflicts` (replay merge-commit reverts). It applies the **Ponytail** minimization ladder (full mode) on every change via an inline prompt directive, the only mechanism that reaches `Agent`-dispatched subagents. Ponytail is also installed natively in-repo as on-demand skills (`.claude/skills/ponytail*`) and `/ponytail*` commands for interactive use in the main session; these do not affect the dev agents.
+The **developer** is a single agent with no modes: it implements the ticket in `TICKET_FILE` (COMPLEX wave, peer-reviewed, writes ADRs for structural decisions, never writes SQL during tickets), or for a SIMPLE dispatch the change described inline via `CHANGE_REQUEST` (no ticket, no planner, on the shared `<base>/simple` worktree; it refuses with `FAILED: out of scope, needs COMPLEX flow` if the change needs a breakdown). Two session-level operations reach it as **skills** loaded on dispatch, run on the same `<base>/simple` worktree: `writing-migrations` (deploy-time SQL generation) and `resolving-rollback-conflicts` (replay merge-commit reverts). It applies the **Ponytail** minimization ladder (full mode) on every change: this is baked into its agent prompt (`developer.md` "Ponytail full mode is always on"), always in context on every dispatch, and the quality-reviewer enforces the same ladder on the resulting diff (flags over-engineering). It is a reasoning directive, not a hook-enforced step. Ponytail is also installed natively in-repo as on-demand skills (`.claude/skills/ponytail*`) and `/ponytail*` commands for interactive use in the main session; these do not affect the dev agents.
## Rules & hooks