mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-10-28 16:32:06 +00:00
Approvals scored 58%. Five survivors, all genuine:
- `ttlSeconds` and `uses` validation was unguarded by any test. An approval
issued with ttl 0 is expired the instant it exists; one with uses 0 can
never be consumed. Either would look like a granted authorization to
whoever asked for it and silently authorize nothing — the confusing
failure rather than the safe one.
- The expiry boundary (`<=` vs `<`) was unpinned. It now asserts that an
approval expiring exactly now is refused, and that one millisecond earlier
it still works, so the boundary is where it claims to be rather than
approximately there. Python uses `<=`, so this is parity as well as the
safer direction.
Approvals now 100%.
Sinks scored 67%. The survivor turned `&&` into `||` in the command-spec
parser, which makes a multi-element spec whose FIRST element contains
whitespace get tokenized — silently discarding every element after it. Losing
an argument changes which command runs, and dropping a `--dry-run` or a target
path is exactly the kind of silent change that matters for a sink being handed
a secret. Sinks now 100%.
Separately, the full suite caught a flaky test of my own: the recovery-split
tamper check rewrote the payload's tail and, depending on the payload's
padding, sometimes reproduced the original string exactly — asserting nothing.
It only failed when a randomized share happened to end the wrong way. Now it
flips a character and asserts the result actually differs before expecting the
throw, plus a second case that tampers at four positions rather than trusting
one. Five consecutive runs are clean.
The agent's mapping was also wrong: agent.ts holds the high-risk session, whose
tests live in highRisk.test.ts, so leaving that suite out scored the agent at
38% and blamed the code for a gap that was really a gap in the harness.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vtx94nXDmNgXEeThUZP4QN
170 lines
6.3 KiB
TypeScript
170 lines
6.3 KiB
TypeScript
/**
|
|
* Sink command-spec parsing.
|
|
*
|
|
* `--exec 'sh -c "..."'` is the most common sink invocation there is, and
|
|
* splitting the spec on whitespace alone broke exactly that shape: sh
|
|
* received the fragments of the quoted script as separate argv entries and
|
|
* died on an unterminated string.
|
|
*/
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
import { parseCommandSpec } from "../src/sinks.js";
|
|
|
|
describe("parseCommandSpec", () => {
|
|
it("keeps a pre-split argv untouched", () => {
|
|
expect(parseCommandSpec(["wc", "-c"])).toEqual(["wc", ["-c"]]);
|
|
});
|
|
|
|
it("splits a single quoted spec on whitespace", () => {
|
|
expect(parseCommandSpec(["wc -c"])).toEqual(["wc", ["-c"]]);
|
|
});
|
|
|
|
it("treats a double-quoted section as one argument", () => {
|
|
expect(parseCommandSpec(['sh -c "echo hello world"'])).toEqual([
|
|
"sh",
|
|
["-c", "echo hello world"],
|
|
]);
|
|
});
|
|
|
|
it("treats a single-quoted section as one argument", () => {
|
|
expect(parseCommandSpec(["sh -c 'echo hello world'"])).toEqual([
|
|
"sh",
|
|
["-c", "echo hello world"],
|
|
]);
|
|
});
|
|
|
|
it("supports quotes nested inside the other quote style", () => {
|
|
expect(parseCommandSpec(["sh -c \"echo 'hi there'\""])).toEqual([
|
|
"sh",
|
|
["-c", "echo 'hi there'"],
|
|
]);
|
|
});
|
|
|
|
it("honours backslash escapes outside single quotes", () => {
|
|
expect(parseCommandSpec(["cmd a\\ b"])).toEqual(["cmd", ["a b"]]);
|
|
expect(parseCommandSpec(["cmd 'a\\ b'"])).toEqual(["cmd", ["a\\ b"]]);
|
|
});
|
|
|
|
it("collapses runs of whitespace", () => {
|
|
expect(parseCommandSpec([" wc -c "])).toEqual(["wc", ["-c"]]);
|
|
});
|
|
|
|
it("does not expand variables — no shell is involved", () => {
|
|
// The secret arrives via the environment; a spec that looks like a shell
|
|
// expansion must reach the child literally rather than being substituted
|
|
// by us.
|
|
expect(parseCommandSpec(["cmd $SEEDPASS_SECRET"])).toEqual([
|
|
"cmd",
|
|
["$SEEDPASS_SECRET"],
|
|
]);
|
|
});
|
|
|
|
it("rejects an unterminated quote instead of guessing", () => {
|
|
expect(() => parseCommandSpec(['sh -c "oops'])).toThrow(/unterminated double quote/);
|
|
expect(() => parseCommandSpec(["sh -c 'oops"])).toThrow(/unterminated single quote/);
|
|
});
|
|
|
|
it("rejects an empty command", () => {
|
|
expect(() => parseCommandSpec([""])).toThrow(/empty command/);
|
|
});
|
|
});
|
|
|
|
import { clipboardSink } from "../src/sinks.js";
|
|
import { mkdtemp, writeFile, readFile, chmod } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import process from "node:process";
|
|
|
|
/**
|
|
* A fake wl-copy/wl-paste pair backed by a state file, placed first on PATH.
|
|
* clipboardSink tries wl-copy first, so these win over any real tools and the
|
|
* test does not depend on a display or a system clipboard.
|
|
*/
|
|
async function fakeClipboard(): Promise<{ dir: string; stateFile: string; restore: () => void }> {
|
|
const dir = await mkdtemp(join(tmpdir(), "seedpass-clip-"));
|
|
const stateFile = join(dir, "clip.txt");
|
|
await writeFile(stateFile, "");
|
|
await writeFile(join(dir, "wl-copy"), `#!/bin/sh\ncat > "${stateFile}"\n`);
|
|
// -n: no trailing newline, matching the real wl-paste flag clipboardSink uses.
|
|
await writeFile(join(dir, "wl-paste"), `#!/bin/sh\ncat "${stateFile}"\n`);
|
|
await chmod(join(dir, "wl-copy"), 0o755);
|
|
await chmod(join(dir, "wl-paste"), 0o755);
|
|
const savedPath = process.env["PATH"];
|
|
process.env["PATH"] = `${dir}:${savedPath ?? ""}`;
|
|
return {
|
|
dir,
|
|
stateFile,
|
|
restore: () => {
|
|
if (savedPath === undefined) delete process.env["PATH"];
|
|
else process.env["PATH"] = savedPath;
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("clipboardSink auto-clear", () => {
|
|
it("copies the secret and, by default, never wipes it", async () => {
|
|
const clip = await fakeClipboard();
|
|
try {
|
|
await clipboardSink("s3cr3t");
|
|
expect(await readFile(clip.stateFile, "utf8")).toBe("s3cr3t");
|
|
// No clear scheduled: it stays put.
|
|
await new Promise((r) => setTimeout(r, 250));
|
|
expect(await readFile(clip.stateFile, "utf8")).toBe("s3cr3t");
|
|
} finally {
|
|
clip.restore();
|
|
}
|
|
});
|
|
|
|
it("wipes the secret after the delay when it is still ours", async () => {
|
|
const clip = await fakeClipboard();
|
|
try {
|
|
const r = await clipboardSink("wipe-me", { clearAfterSeconds: 0.15 });
|
|
expect(r.detail).toContain("clears in");
|
|
expect(await readFile(clip.stateFile, "utf8")).toBe("wipe-me");
|
|
await new Promise((res) => setTimeout(res, 400));
|
|
expect(await readFile(clip.stateFile, "utf8")).toBe("");
|
|
} finally {
|
|
clip.restore();
|
|
}
|
|
});
|
|
|
|
it("leaves a value the user copied since the secret untouched", async () => {
|
|
const clip = await fakeClipboard();
|
|
try {
|
|
await clipboardSink("old-secret", { clearAfterSeconds: 0.15 });
|
|
// The user copies something else before the timer fires.
|
|
await writeFile(clip.stateFile, "user's own copy");
|
|
await new Promise((res) => setTimeout(res, 400));
|
|
expect(await readFile(clip.stateFile, "utf8")).toBe("user's own copy");
|
|
} finally {
|
|
clip.restore();
|
|
}
|
|
});
|
|
})
|
|
|
|
describe("command spec parsing keeps every argument", () => {
|
|
it("does not tokenize when more than one element was supplied", () => {
|
|
// Mutation testing found this unguarded: turning the `&&` into `||` makes
|
|
// a multi-element spec whose FIRST element contains whitespace get
|
|
// tokenized, silently discarding every element after it. Losing an
|
|
// argument changes which command runs — dropping a `--dry-run` or a
|
|
// target path is exactly the kind of silent change that matters for a
|
|
// sink handed a secret.
|
|
expect(parseCommandSpec(["echo hi", "there"])).toEqual(["echo hi", ["there"]]);
|
|
expect(parseCommandSpec(["wc", "-c"])).toEqual(["wc", ["-c"]]);
|
|
expect(parseCommandSpec(["a b", "c d", "e"])).toEqual(["a b", ["c d", "e"]]);
|
|
});
|
|
|
|
it("tokenizes only a lone element containing whitespace", () => {
|
|
expect(parseCommandSpec(["wc -c"])).toEqual(["wc", ["-c"]]);
|
|
// A lone element with no whitespace needs no splitting, and splitting it
|
|
// must not change it.
|
|
expect(parseCommandSpec(["ls"])).toEqual(["ls", []]);
|
|
});
|
|
|
|
it("refuses an empty command rather than running something unintended", () => {
|
|
expect(() => parseCommandSpec([])).toThrow(/empty command/);
|
|
expect(() => parseCommandSpec([""])).toThrow(/empty command/);
|
|
});
|
|
});
|