Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
44 changes: 44 additions & 0 deletions src/check-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
110 changes: 67 additions & 43 deletions src/check-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,83 +609,107 @@ async function checkSecretsInCode(): Promise<SecurityCheckResult> {
}

/**
* 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<SecurityCheckResult> {
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",
};
}
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<SecurityCheckResult> {
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);
}

/**
Expand Down
Loading