diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 71299dd8..be24ef89 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -27,6 +27,10 @@ jobs: # Protocol schema, SKILL.md frontmatter, README badge count. run: bash scripts/validate-manifests.sh + - name: No credential-shaped strings in tracked files + # Test fixtures use fakeSecret(prefix, body) so no whole token sits in the repo. + run: node scripts/check-token-literals.mjs + plugin-validate: # Free gate: no model calls, no API key. `claude plugin validate` checks each # manifest plus its skills, agents and commands. diff --git a/CLAUDE.md b/CLAUDE.md index e8dde421..bd9ac008 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -153,6 +153,12 @@ Flag any SKILL.md content that contains: --- +## Test fixtures that look like secrets + +Never write a whole token-shaped string (GitHub, Google, Stripe, npm, Slack, webhook URLs) into any file, even a fake one in a test. This repo is public: GitHub secret scanning raises a public-leak alert, and the string invites a closer look at the repo. Build fixtures with `fakeSecret(prefix, body)` (`packages/core/__tests__/helpers/fake-secret.ts`, `apps/desktop/src/test-utils/fake-secret.ts`). `scripts/check-token-literals.mjs` fails CI on a whole token. + +--- + ## Release checklist 1. Bump `version` in `plugins//.claude-plugin/plugin.json` and `.claude-plugin/marketplace.json` (must match) diff --git a/apps/desktop/src/pages/harness/__tests__/ShareSheet.test.tsx b/apps/desktop/src/pages/harness/__tests__/ShareSheet.test.tsx index 769a5427..aec890ca 100644 --- a/apps/desktop/src/pages/harness/__tests__/ShareSheet.test.tsx +++ b/apps/desktop/src/pages/harness/__tests__/ShareSheet.test.tsx @@ -4,13 +4,14 @@ import type { HarnessConfig } from "@harness-kit/core"; import { buildProfilePrompt, buildProfileShare } from "@harness-kit/core"; import ShareSheet from "../ShareSheet"; import { ToastProvider } from "../../../components/ToastProvider"; +import { fakeSecret } from "../../../test-utils/fake-secret"; const mockSaveShareFile = vi.fn(); vi.mock("../../../lib/tauri", () => ({ saveShareFile: (...args: unknown[]) => mockSaveShareFile(...args), })); -const SECRET = "ghp_abcdefghijklmnopqrstuvwxyz0123456789"; +const SECRET = fakeSecret("ghp_", "abcdefghijklmnopqrstuvwxyz0123456789"); const withSecret: HarnessConfig = { version: "1", metadata: { name: "alice-setup", description: "Alice's tools" }, diff --git a/apps/desktop/src/test-utils/fake-secret.ts b/apps/desktop/src/test-utils/fake-secret.ts new file mode 100644 index 00000000..b641b1d2 --- /dev/null +++ b/apps/desktop/src/test-utils/fake-secret.ts @@ -0,0 +1,15 @@ +/** + * Test-only credential-shaped strings. NOT real credentials. + * + * Fixtures for the secret scrubber need values shaped like real tokens. Writing + * them whole puts key-shaped text in a public repo: secret scanners raise + * alerts, and anyone scanning the repo sees what looks like a leak. Building + * each one from a prefix and a body at run time keeps the source free of whole + * tokens while the test sees the exact same string. + * + * `scripts/check-token-literals.mjs` (repo root) fails CI when a whole token is written + * into a file instead. + */ +export function fakeSecret(prefix: string, body: string): string { + return prefix + body; +} diff --git a/packages/core/__tests__/helpers/fake-secret.ts b/packages/core/__tests__/helpers/fake-secret.ts new file mode 100644 index 00000000..d3093d65 --- /dev/null +++ b/packages/core/__tests__/helpers/fake-secret.ts @@ -0,0 +1,15 @@ +/** + * Test-only credential-shaped strings. NOT real credentials. + * + * Fixtures for the secret scrubber need values shaped like real tokens. Writing + * them whole puts key-shaped text in a public repo: secret scanners raise + * alerts, and anyone scanning the repo sees what looks like a leak. Building + * each one from a prefix and a body at run time keeps the source free of whole + * tokens while the test sees the exact same string. + * + * `scripts/check-token-literals.mjs` fails CI when a whole token is written + * into a file instead. + */ +export function fakeSecret(prefix: string, body: string): string { + return prefix + body; +} diff --git a/packages/core/__tests__/import-inventory.test.ts b/packages/core/__tests__/import-inventory.test.ts index 5f497ec1..526e3c5c 100644 --- a/packages/core/__tests__/import-inventory.test.ts +++ b/packages/core/__tests__/import-inventory.test.ts @@ -5,6 +5,7 @@ import { buildMachineInventory } from "../src/observe/machine-inventory.js"; import { validateHarness } from "../src/schema/validate.js"; import type { ObserveOptions } from "../src/observe/observe-surface.js"; import { MockFsProvider } from "./helpers/mock-fs.js"; +import { fakeSecret } from "./helpers/fake-secret.js"; const HOME = "/home/user"; const OPTS: ObserveOptions = { projectRoot: null, homeRoot: HOME, platform: "darwin" }; @@ -14,13 +15,13 @@ const CLAUDE_JSON = JSON.stringify({ github: { command: "npx", args: ["-y", "gh-mcp"], - env: { GITHUB_TOKEN: "ghp_abcdefghijklmnopqrstuvwxyz0123456789", PORT: "5432" }, + env: { GITHUB_TOKEN: fakeSecret("ghp_", "abcdefghijklmnopqrstuvwxyz0123456789"), PORT: "5432" }, }, remote: { type: "http", url: "https://example.com/mcp" }, authed: { type: "http", url: "https://authed.example.com/mcp", - headers: { Authorization: "Bearer ghp_abcdefghijklmnopqrstuvwxyz0123456789", "X-Region": "us" }, + headers: { Authorization: `Bearer ${fakeSecret("ghp_", "abcdefghijklmnopqrstuvwxyz0123456789")}`, "X-Region": "us" }, }, }, }); diff --git a/packages/core/__tests__/normalize.test.ts b/packages/core/__tests__/normalize.test.ts index bfafa07b..7680b681 100644 --- a/packages/core/__tests__/normalize.test.ts +++ b/packages/core/__tests__/normalize.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect } from "vitest"; import { normalizeResource, normalizeObservation } from "../src/observe/normalize.js"; import type { ObservedResource, SurfaceObservation } from "../src/observe/observe-surface.js"; +import { fakeSecret } from "./helpers/fake-secret.js"; function mcpResource( value: unknown, @@ -192,7 +193,7 @@ describe("normalizeResource — mcp-server inline secrets", () => { it("an element matching a credential value shape is placeholdered", () => { const a = normalizeResource( - mcpResource({ command: "run", args: ["ghp_abcdefghijklmnopqrstu", "input.txt"] }), + mcpResource({ command: "run", args: [fakeSecret("ghp_", "abcdefghijklmnopqrstu"), "input.txt"] }), ); expect((a.canonicalForm as { args: string[] }).args).toEqual(["", "input.txt"]); }); @@ -260,7 +261,7 @@ describe("normalizeResource — url query/path secrets", () => { it("placeholders credential-shaped query values under non-sensitive names; keyspace-like names stay verbatim", () => { const cred = normalizeResource( - mcpResource({ transport: "http", url: "https://x.test/mcp?blob=ghp_abcdefghijklmnopqrstu" }), + mcpResource({ transport: "http", url: `https://x.test/mcp?blob=${fakeSecret("ghp_", "abcdefghijklmnopqrstu")}` }), ); expect((cred.canonicalForm as { url: string }).url).toBe("https://x.test/mcp?blob="); const plain = normalizeResource( @@ -280,7 +281,7 @@ describe("normalizeResource — widened value shapes and key tokens", () => { ); expect((jwt.canonicalForm as { env: Record }).env.SOME_VAR).toBe(""); const slack = normalizeResource( - mcpResource({ command: "run", env: { SOME_VAR: "xoxb-123456789012-abcdefghij" } }), + mcpResource({ command: "run", env: { SOME_VAR: fakeSecret("xoxb-", "123456789012-abcdefghij") } }), ); expect((slack.canonicalForm as { env: Record }).env.SOME_VAR).toBe(""); }); @@ -304,7 +305,7 @@ describe("normalizeResource — widened value shapes and key tokens", () => { mcpResource({ command: "run", env: { - NESTED: { token: "ghp_abcdefghijklmnopqrstu", note: "hello" } as unknown as string, + NESTED: { token: fakeSecret("ghp_", "abcdefghijklmnopqrstu"), note: "hello" } as unknown as string, }, }), ); diff --git a/packages/core/__tests__/plugin-inventory.test.ts b/packages/core/__tests__/plugin-inventory.test.ts index 90f6b30a..6f7d6090 100644 --- a/packages/core/__tests__/plugin-inventory.test.ts +++ b/packages/core/__tests__/plugin-inventory.test.ts @@ -16,6 +16,7 @@ import { planCellAction, syncCliCommand } from "../src/write/plan-cell-action.js import { buildAgentPrompt } from "../src/write/agent-prompt.js"; import { applyCellAction } from "../src/write/apply-cell-action.js"; import { MockFsProvider } from "./helpers/mock-fs.js"; +import { fakeSecret } from "./helpers/fake-secret.js"; /** * Plugin and marketplace enumeration (AC-4). @@ -511,7 +512,7 @@ describe("marketplace sources cannot carry credentials off the machine", () => { // credentials is the shape both surfaces genuinely record for a private // marketplace, and `harness-kit status --json` is what users paste into // bug reports. - const TOKEN = "ghp_EXAMPLETOKEN0000000000000000000000"; + const TOKEN = fakeSecret("ghp_", "EXAMPLETOKEN0000000000000000000000"); async function sourcesFor(files: Record, surface: "claude-code" | "codex") { const fs = new MockFsProvider(files, PROJECT, HOME); diff --git a/packages/core/__tests__/profile-share.test.ts b/packages/core/__tests__/profile-share.test.ts index d0768be9..af4970e1 100644 --- a/packages/core/__tests__/profile-share.test.ts +++ b/packages/core/__tests__/profile-share.test.ts @@ -2,6 +2,18 @@ import { describe, expect, it } from "vitest"; import { parse } from "yaml"; import { buildProfilePrompt, buildProfileShare } from "../src/portability/share.js"; import type { HarnessConfig } from "../src/types.js"; +import { fakeSecret } from "./helpers/fake-secret.js"; + +// Built at run time; see helpers/fake-secret.ts. None of these are real. +const FAKE_GITHUB_TOKEN = fakeSecret("ghp_", "abcdefghijklmnopqrstuvwxyz0123456789"); +const FAKE_GITHUB_PAT = fakeSecret("github_pat_", "11ABCDEFG0123456789_abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRS"); +const FAKE_STRIPE_KEY = fakeSecret("sk_live_", "51HxStripeSecret0123"); +const FAKE_STRIPE_KEY_2 = fakeSecret("sk_live_", "SECRETFFF666abc"); +const FAKE_NPM_TOKEN = fakeSecret("npm_", "abcdefghijklmnopqrstuvwxyz0123456789"); +const FAKE_GITLAB_TOKEN = fakeSecret("glpat-", "abcdefghij0123456789"); +const FAKE_GOOGLE_KEY = fakeSecret("AIza", "SyA1234567890abcdefghijklmnopqrstuv"); +const FAKE_SLACK_WEBHOOK = fakeSecret("https://hooks.slack.com/services/", "T000/B000/XXXXsecretXXXXabcd"); +const FAKE_DISCORD_WEBHOOK = fakeSecret("https://discord.com/api/webhooks/", "123456/abcDEFsecretTOKENxyz"); const profile = (extra: Partial = {}): HarnessConfig => ({ version: "1", @@ -11,8 +23,8 @@ const profile = (extra: Partial = {}): HarnessConfig => ({ github: { transport: "stdio", command: "gh-mcp", - args: ["--token", "ghp_abcdefghijklmnopqrstuvwxyz0123456789"], - env: { GITHUB_TOKEN: "ghp_abcdefghijklmnopqrstuvwxyz0123456789" }, + args: ["--token", FAKE_GITHUB_TOKEN], + env: { GITHUB_TOKEN: FAKE_GITHUB_TOKEN }, }, }, ...extra, @@ -21,7 +33,7 @@ const profile = (extra: Partial = {}): HarnessConfig => ({ describe("profile share export (AC-25)", () => { it("strips secret values with the capture sanitizer and declares what to set", () => { const share = buildProfileShare(profile()); - expect(share.yaml).not.toContain("ghp_abcdefghijklmnopqrstuvwxyz0123456789"); + expect(share.yaml).not.toContain(FAKE_GITHUB_TOKEN); expect(share.findings.length).toBeGreaterThan(0); const names = share.requiredEnv.map((entry) => entry.name); for (const finding of share.findings) expect(names).toContain(finding.variable); @@ -66,7 +78,7 @@ describe("profile share export (AC-25)", () => { describe("profile agent prompt (AC-25)", () => { it("carries the sanitized harness.yaml and never the secret", () => { const prompt = buildProfilePrompt(profile()); - expect(prompt).not.toContain("ghp_abcdefghijklmnopqrstuvwxyz0123456789"); + expect(prompt).not.toContain(FAKE_GITHUB_TOKEN); expect(prompt).toContain("alice-setup"); expect(prompt).toContain("gh-mcp"); }); @@ -110,7 +122,7 @@ describe("profile agent prompt (AC-25)", () => { describe("profile share: adversarial secrets (review round)", () => { const LEAKS: Array<[string, Partial, string]> = [ - ["token-only URL userinfo", { "mcp-servers": { r: { transport: "sse", url: "https://ghp_abcdefghijklmnopqrstuvwxyz0123456789@host.example/mcp" } } }, "ghp_abcdefghijklmnopqrstuvwxyz0123456789"], + ["token-only URL userinfo", { "mcp-servers": { r: { transport: "sse", url: `https://${FAKE_GITHUB_TOKEN}@host.example/mcp` } } }, FAKE_GITHUB_TOKEN], ["user:password URL userinfo", { "mcp-servers": { r: { transport: "sse", url: "https://bob:hunter2pass@host.example/mcp" } } }, "hunter2pass"], ["URL fragment param", { "mcp-servers": { r: { transport: "sse", url: "https://h.example/cb#access_token=FRAGSECRET99" } } }, "FRAGSECRET99"], ["query secret inside an arg", { "mcp-servers": { r: { transport: "stdio", command: "npx", args: ["mcp-remote", "https://h.example/sse?api_key=ARGQSECRET77"] } } }, "ARGQSECRET77"], @@ -122,7 +134,7 @@ describe("profile share: adversarial secrets (review round)", () => { ["header value after --header", { "mcp-servers": { r: { transport: "stdio", command: "x", args: ["--header", "X-API-Key: HDRSECRET64"] } } }, "HDRSECRET64"], ["docker -e KEY=value", { "mcp-servers": { r: { transport: "stdio", command: "docker", args: ["run", "-e", "API_KEY=DOCKERSECRET2", "img"] } } }, "DOCKERSECRET2"], ["JSON inside an arg", { "mcp-servers": { r: { transport: "stdio", command: "x", args: ['{"apiKey":"JSONARGSECRET3"}'] } } }, "JSONARGSECRET3"], - ["Stripe live key", { "mcp-servers": { r: { transport: "stdio", command: "x", env: { STRIPE_SK: "sk_live_51HxStripeSecret0123" } } } }, "sk_live_51HxStripeSecret0123"], + ["Stripe live key", { "mcp-servers": { r: { transport: "stdio", command: "x", env: { STRIPE_SK: FAKE_STRIPE_KEY } } } }, FAKE_STRIPE_KEY], ]; for (const [label, extra, secret] of LEAKS) { @@ -195,14 +207,14 @@ describe("profile share: second adversarial round", () => { ["KEY=value with &", prose("TOKEN=abc&TAILSECRET303"), "TAILSECRET303"], ["quoted value with spaces", prose('password="correct horse battery"'), "horse battery"], ["secret next to a reference", prose("export A=${HARNESS_A}; password=hunter2xyz"), "hunter2xyz"], - ["stripe key next to a reference", prose("Set ${HARNESS_FOO} then export STRIPE=sk_live_SECRETFFF666abc"), "sk_live_SECRETFFF666abc"], + ["stripe key next to a reference", prose(`Set \${HARNESS_FOO} then export STRIPE=${FAKE_STRIPE_KEY_2}`), FAKE_STRIPE_KEY_2], ["secret glued to a reference", prose("REALSECRETzz99${HARNESS_X}"), "REALSECRETzz99"], - ["github fine-grained PAT", prose("use github_pat_11ABCDEFG0123456789_abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRS"), "github_pat_11ABCDEFG0123456789"], - ["npm token", prose("npm_abcdefghijklmnopqrstuvwxyz0123456789"), "npm_abcdefghijklmnopqrstuvwxyz0123456789"], - ["gitlab token", prose("glpat-abcdefghij0123456789"), "glpat-abcdefghij0123456789"], - ["google api key", prose("AIzaSyA1234567890abcdefghijklmnopqrstuv"), "AIzaSyA1234567890abcdefghijklmnopqrstuv"], - ["slack webhook path", prose("post to https://hooks.slack.com/services/T000/B000/XXXXsecretXXXXabcd"), "XXXXsecretXXXXabcd"], - ["discord webhook path", prose("https://discord.com/api/webhooks/123456/abcDEFsecretTOKENxyz"), "abcDEFsecretTOKENxyz"], + ["github fine-grained PAT", prose(`use ${FAKE_GITHUB_PAT}`), FAKE_GITHUB_PAT.slice(0, 30)], + ["npm token", prose(FAKE_NPM_TOKEN), FAKE_NPM_TOKEN], + ["gitlab token", prose(FAKE_GITLAB_TOKEN), FAKE_GITLAB_TOKEN], + ["google api key", prose(FAKE_GOOGLE_KEY), FAKE_GOOGLE_KEY], + ["slack webhook path", prose(`post to ${FAKE_SLACK_WEBHOOK}`), "XXXXsecretXXXXabcd"], + ["discord webhook path", prose(FAKE_DISCORD_WEBHOOK), "abcDEFsecretTOKENxyz"], ["password with an empty user", prose("connect to https://:emptyUserPw99@h.example/db"), "emptyUserPw99"], ["number under a sensitive key", { "mcp-servers": { r: { transport: "stdio", command: "x", env: { PASSWORD: 987654321 as unknown as string } } } }, "987654321"], ["array under a sensitive key", { plugins: [{ name: "p", source: "o/r", config: { API_KEYS: ["LEAK10aaaa", "LEAK11bbbb"] } }] }, "LEAK10aaaa"], diff --git a/scripts/check-token-literals.mjs b/scripts/check-token-literals.mjs new file mode 100644 index 00000000..b8a33aff --- /dev/null +++ b/scripts/check-token-literals.mjs @@ -0,0 +1,57 @@ +#!/usr/bin/env node +// Fails when a tracked file contains a whole credential-shaped string. +// +// Test fixtures for the secret scrubber need token-shaped values. Written +// whole, they look like leaks to secret scanners and to anyone scanning this +// public repo. Build them at run time with `fakeSecret(prefix, body)` instead: +// packages/core/__tests__/helpers/fake-secret.ts +// apps/desktop/src/test-utils/fake-secret.ts +// +// Prints the file, line and token kind, never the matched text. + +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; + +const SHAPES = [ + ["GitHub token", /\bgh[pousr]_[A-Za-z0-9]{20,}/], + ["GitHub fine-grained PAT", /\bgithub_pat_[A-Za-z0-9_]{20,}/], + ["GitLab token", /\bglpat-[A-Za-z0-9_-]{20,}/], + ["npm token", /\bnpm_[A-Za-z0-9]{36}/], + ["Google API key", /\bAIza[0-9A-Za-z_-]{35}/], + ["AWS access key", /\bAKIA[0-9A-Z]{16}\b/], + ["Stripe key", /\b[sr]k_live_[A-Za-z0-9]{10,}/], + ["Anthropic/OpenAI key", /\bsk-(?:ant|proj)-[A-Za-z0-9_-]{20,}/], + ["Slack token", /\bxox[abprs]-[A-Za-z0-9-]{10,}/], + ["Slack webhook", /hooks\.slack\.com\/services\/T[A-Za-z0-9]+\/B[A-Za-z0-9]+\/[A-Za-z0-9]+/], + ["Discord webhook", /discord(?:app)?\.com\/api\/webhooks\/\d+\/[A-Za-z0-9_-]+/], + ["Private key block", /-----BEGIN [A-Z ]*PRIVATE KEY-----/], +]; + +const SELF = "scripts/check-token-literals.mjs"; +const files = execFileSync("git", ["ls-files", "-z"], { encoding: "utf8" }) + .split("\0") + .filter((f) => f && f !== SELF); + +const hits = []; +for (const file of files) { + let text; + try { + text = readFileSync(file, "utf8"); + } catch { + continue; // deleted in the working tree, or unreadable + } + if (text.includes("\0")) continue; // binary + const lines = text.split("\n"); + lines.forEach((line, i) => { + for (const [kind, re] of SHAPES) { + if (re.test(line)) hits.push(`${file}:${i + 1}: ${kind}`); + } + }); +} + +if (hits.length) { + console.error("Credential-shaped strings found in tracked files:\n " + hits.join("\n ")); + console.error("\nIf it is a test fixture, build it with fakeSecret(prefix, body). If it is real, rotate it."); + process.exit(1); +} +console.log(`No credential-shaped strings in ${files.length} tracked files.`);