diff --git a/CHANGELOG.md b/CHANGELOG.md index 383e1ad4..fdc4dd5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] +## [1.25.1] - 2026-06-24 + +### Fixed + +- **`kit check` Socket scan no longer fails open — a not-logged-in Socket can't masquerade as "passed".** `checkSocket` previously treated any non-JSON `socket check` output as "passed" (`catch { /* passed */ }` + a bare exit-0 → `pass`), so an installed-but-unauthenticated Socket — which appears to run while checking nothing — could report a green "no supply chain issues detected" and give false assurance. Now a `pass` requires POSITIVE proof the scan ran (valid result JSON); not-logged-in / unparseable output / non-zero exit all surface loudly as **"socket NOT scanning — supply chain UNVERIFIED"** with a `socket login` hint, never as pass. Decision logic extracted to a pure, fixture-tested `classifySocketResult`. (Same fail-closed principle as #74 for `kit scan`; `checkSemgrep` was already fail-closed.) + ## [1.25.0] - 2026-06-24 ### Added diff --git a/package-lock.json b/package-lock.json index 055e1a31..6bb236da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sandstream-kit", - "version": "1.25.0", + "version": "1.25.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sandstream-kit", - "version": "1.25.0", + "version": "1.25.1", "license": "MIT", "workspaces": [ "packages/*" diff --git a/package.json b/package.json index 3fd739cf..60d4cf7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sandstream-kit", - "version": "1.25.0", + "version": "1.25.1", "description": "developer kit. zero LLM, local-first, multi-vault. one command from git clone to working dev environment.", "license": "MIT", "funding": "https://buymeacoffee.com/sandstream", diff --git a/src/check-security.test.ts b/src/check-security.test.ts index b1dcd654..75005496 100644 --- a/src/check-security.test.ts +++ b/src/check-security.test.ts @@ -5,8 +5,52 @@ import { parseTrivyMisconfigCount, parseOsvVulnCount, parseTrivyVulnCount, + classifySocketResult, } from "./check-security.js"; +describe("classifySocketResult (fail-closed)", () => { + it("never passes when Socket is not logged in (the false-green guard)", () => { + for (const raw of [ + "Please run `socket login` first", + "Error: unauthenticated", + "401 Unauthorized", + "Set SOCKET_API_TOKEN to continue", + ]) { + const r = classifySocketResult(raw, false); + assert.strictEqual(r.status, "warn", `expected warn for: ${raw}`); + assert.match(r.detail, /UNVERIFIED|not logged in/); + assert.strictEqual(r.suggestion, "socket login"); + } + }); + + it("passes ONLY on a valid scan result with zero issues", () => { + const r = classifySocketResult(JSON.stringify({ issues: [] }), true); + assert.strictEqual(r.status, "pass"); + }); + + it("fails on critical/high issues, warns on lower issues", () => { + assert.strictEqual( + classifySocketResult(JSON.stringify({ issues: [{ severity: "critical" }] }), false).status, + "fail", + ); + assert.strictEqual( + classifySocketResult(JSON.stringify({ issues: [{ severity: "low" }] }), true).status, + "warn", + ); + }); + + it("does NOT pass on unparseable output, even with exit 0 (no proof of scan)", () => { + const r = classifySocketResult("some human-readable banner, not JSON", true); + assert.strictEqual(r.status, "warn"); + assert.match(r.detail, /UNVERIFIED/); + }); + + it("warns (not pass) on non-zero exit with no parseable output", () => { + const r = classifySocketResult("", false); + assert.strictEqual(r.status, "warn"); + }); +}); + describe("parseTrivyMisconfigCount", () => { it("counts only HIGH/CRITICAL misconfigurations", () => { const json = JSON.stringify({ diff --git a/src/check-security.ts b/src/check-security.ts index d9424616..3802cc1a 100644 --- a/src/check-security.ts +++ b/src/check-security.ts @@ -609,48 +609,44 @@ async function checkSecretsInCode(): Promise { } /** - * Check for supply chain attacks using Socket CLI. - * Detects behavioral anomalies (obfuscated files, unexpected network calls, install scripts) - * that npm audit misses -catches intentional malware like node-ipc and compromised packages. + * Classify `socket check --json` output into a result (pure — fixture-tested). + * + * FAIL CLOSED: a `pass` requires POSITIVE proof the scan ran (valid result JSON). + * The dangerous case is a Socket that's installed but NOT authenticated — it can + * appear to "run" yet check nothing, and a fail-open `pass` would give false + * assurance the supply chain is covered. So not-logged-in / unparseable output / + * non-zero exit all surface LOUDLY as "not scanning — UNVERIFIED", never as pass. + * (Same principle as #74 for `kit scan`.) */ -async function checkSocket(): Promise { - try { - await access(resolve(process.cwd(), "package.json")); - } catch { - return { - category: "supply-chain", - name: "socket scan", - status: "skip", - detail: "no package.json found", - }; - } - - // Resolve mise-first: kit installs scanners via mise, whose shims aren't on - // kit's PATH. A bare "socket" lookup would miss a mise-installed one. - const socketBin = await resolveToolBin("socket"); - if (!socketBin) { +export function classifySocketResult(raw: string, ok: boolean): SecurityCheckResult { + const base = { category: "supply-chain", name: "socket scan" } as const; + if ( + /(socket login|log[\s-]?in|unauthenticat|not authenticated|api[\s_-]*token|forbidden|\b401\b|\b403\b)/i.test( + raw, + ) + ) { return { - category: "supply-chain", - name: "socket scan", + ...base, status: "warn", - detail: "socket not installed -supply chain malware undetected", + detail: "socket NOT scanning — not logged in; supply chain UNVERIFIED", severity: "medium", - suggestion: "mise use npm:@socketsecurity/cli (or: npm install -g @socketsecurity/cli)", + suggestion: "socket login", }; } - const result = await execFileNoThrow(socketBin, ["check", "--json"], { timeout: 60_000 }); - const raw = result.stdout || result.stderr; - + let parsed: { issues?: { severity?: string }[]; alerts?: { severity?: string }[] } | null = null; try { - const parsed = JSON.parse(raw); - const issues: Array<{ severity?: string }> = parsed.issues ?? parsed.alerts ?? []; - const critical = issues.filter((i) => i.severity === "critical" || i.severity === "high"); + parsed = JSON.parse(raw); + } catch { + parsed = null; + } + if (parsed) { + const issues = parsed.issues ?? parsed.alerts ?? []; + const critical = issues.filter((i) => i.severity === "critical" || i.severity === "high"); if (critical.length > 0) { return { - category: "supply-chain", - name: "socket scan", + ...base, status: "fail", detail: `${critical.length} critical/high supply chain issue(s) -run: socket check`, severity: "critical", @@ -658,34 +654,62 @@ async function checkSocket(): Promise { } if (issues.length > 0) { return { - category: "supply-chain", - name: "socket scan", + ...base, status: "warn", detail: `${issues.length} supply chain warning(s) -run: socket check`, severity: "medium", }; } + // Valid scan result with zero issues — the ONLY path that earns a pass. + return { ...base, status: "pass", detail: "no supply chain issues detected" }; + } + + // No parseable result (and no recognized auth error): cannot confirm a scan + // happened — never pass on that assumption. + return { + ...base, + status: "warn", + detail: ok + ? "socket check returned no parseable result — supply chain UNVERIFIED" + : "socket check failed -verify installation or run: socket login", + severity: "medium", + suggestion: "socket login", + }; +} + +/** + * Check for supply chain attacks using Socket CLI. + * Detects behavioral anomalies (obfuscated files, unexpected network calls, install scripts) + * that npm audit misses -catches intentional malware like node-ipc and compromised packages. + */ +async function checkSocket(): Promise { + try { + await access(resolve(process.cwd(), "package.json")); } catch { - // Non-JSON output: socket check passed (exit 0, human-readable) + return { + category: "supply-chain", + name: "socket scan", + status: "skip", + detail: "no package.json found", + }; } - if (!result.ok) { + // Resolve mise-first: kit installs scanners via mise, whose shims aren't on + // kit's PATH. A bare "socket" lookup would miss a mise-installed one. + const socketBin = await resolveToolBin("socket"); + if (!socketBin) { return { category: "supply-chain", name: "socket scan", status: "warn", - detail: "socket check failed -verify installation or run: socket login", + detail: "socket not installed -supply chain malware undetected", severity: "medium", - suggestion: "socket login", + suggestion: "mise use npm:@socketsecurity/cli (or: npm install -g @socketsecurity/cli)", }; } - return { - category: "supply-chain", - name: "socket scan", - status: "pass", - detail: "no supply chain issues detected", - }; + const result = await execFileNoThrow(socketBin, ["check", "--json"], { timeout: 60_000 }); + return classifySocketResult(result.stdout || result.stderr, result.ok); } /**