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
54 changes: 52 additions & 2 deletions src/commands/triage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { triageVaultConfig } from "../vault-triage.js";
export async function cmdTriage(): Promise<boolean> {
const args = process.argv.slice(3);
const sandbox = hasFlag(args, "--sandbox");
const filtered = args.filter((a) => a !== "--sandbox");
const deep = hasFlag(args, "--deep");
const filtered = args.filter((a) => a !== "--sandbox" && a !== "--deep");
const typeArg = filtered[0];
// `check-deps` is a pre-commit subcommand handled below before we narrow
// to TriageType; the rest of this function works against TriageType only.
Expand Down Expand Up @@ -44,6 +45,9 @@ export async function cmdTriage(): Promise<boolean> {
);
console.log(" kit triage repo <github-url> Evaluate GitHub repository");
console.log(" kit triage skill <path|name> Evaluate Claude Code / agent skill");
console.log(
" kit triage skill <path|name> --deep + SkillSpector (NVIDIA) static Stage 1 (no LLM, no egress) when installed",
);
console.log(
" kit triage mcp <server> --tools <f> Evaluate MCP tool metadata (poisoning) + pin against drift",
);
Expand Down Expand Up @@ -127,7 +131,17 @@ export async function cmdTriage(): Promise<boolean> {
);
}

const overall = result.passed && sandboxClean;
// --deep on a skill: delegate to SkillSpector's STATIC Stage 1 (no LLM, no egress). Fail-closed.
let deepClean = true;
if (deep && type === "skill") {
deepClean = await deepSkillScan(target);
} else if (deep && type !== "skill") {
console.log(
`\n${c.dim}(--deep currently only applies to skill; ignored for ${type})${c.reset}`,
);
}

const overall = result.passed && sandboxClean && deepClean;
if (!overall) {
console.log(`\n${c.yellow}⚠️ Review warnings above before proceeding.${c.reset}`);
}
Expand All @@ -143,6 +157,42 @@ export async function cmdTriage(): Promise<boolean> {
return overall;
}

/**
* `kit triage skill … --deep` helper: run SkillSpector's static Stage 1 (no LLM, no egress) and fold
* its normalized findings into the verdict. Returns `false` only on a real high/critical finding or a
* scan error; an ABSENT delegate is surfaced honestly and returns `true` (deep didn't run — the base
* triage verdict still governs; kit never claims a deep-clean it didn't perform).
*/
async function deepSkillScan(target: string): Promise<boolean> {
const { runSkillspectorStage1, SKILLSPECTOR_SOURCE } =
await import("../skillspector-delegate.js");
console.log(
`\n${c.bold}Deep scan (${SKILLSPECTOR_SOURCE}, static — no LLM, no egress):${c.reset}`,
);
const deepRes = await runSkillspectorStage1(target);
if (deepRes.status === "unavailable") {
console.log(` ${c.yellow}! ${deepRes.detail}${c.reset}`);
return true;
}
if (deepRes.status === "error") {
console.log(` ${c.red}✗ deep scan errored: ${deepRes.detail}${c.reset}`);
return false;
}
if (deepRes.findings.length === 0) {
console.log(` ${c.green}✓ no findings from the deep static scan${c.reset}`);
return true;
}
for (const f of deepRes.findings) {
const sev = f.severity ?? "info";
const tag =
sev === "critical" || sev === "high"
? `${c.red}[${sev.toUpperCase()}]${c.reset}`
: `${c.yellow}[${sev}]${c.reset}`;
console.log(` ${tag} ${f.detail}`);
}
return !(deepRes.worst === "critical" || deepRes.worst === "high");
}

/**
* `kit triage vault-config` — triage the project's secret-backend SELECTION (`.kit.toml`
* `secrets.store` + per-key `source`): flag an unknown/typo'd backend (silently no vault) and
Expand Down
4 changes: 2 additions & 2 deletions src/doctor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ describe("runDoctor", () => {
}
});

it("exec-broker runtime: skips when enforce_runtime is not opted in", async () => {
it("exec-broker runtime: skips when no [scope] is declared (nothing to mediate)", async () => {
const tmpDir = join(tmpdir(), `kit-doctor-test-${process.pid}-rt-skip`);
await mkdir(tmpDir, { recursive: true });
try {
const result = await runDoctor({}, tmpDir);
const rt = result.checks.find((c) => c.name === "exec-broker runtime");
assert.ok(rt, "exec-broker runtime check should always be present");
assert.equal(rt.status, "skip");
assert.ok(rt.detail.includes("enforce_runtime"), `unexpected detail: ${rt.detail}`);
assert.ok(rt.detail.includes("no [scope]"), `unexpected detail: ${rt.detail}`);
} finally {
await rm(tmpDir, { recursive: true });
}
Expand Down
8 changes: 6 additions & 2 deletions src/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,17 @@ async function scopeDegradationStatus(cwd: string): Promise<"warn" | "fail"> {
async function checkBrokerRuntime(cwd: string): Promise<DoctorCheck> {
const name = "exec-broker runtime";
const category = "security";
const { runtimeMode, policy } = await profileBrokerPolicy(cwd);
const { runtimeMode, policy, regime } = await profileBrokerPolicy(cwd);
if (runtimeMode === "off") {
// Default-on: a declared scope mediates in observe by default, so "off" means either no scope is
// declared here, or the scope explicitly opted OUT with enforce_runtime = false.
return {
name,
status: "skip",
detail:
'MCP-runtime mediation not opted in — set [scope].enforce_runtime = true (or "observe" for a dry-run) and re-sign to mediate governed MCP ops against the scope',
regime === "none"
? "no [scope] declared — nothing to mediate at the MCP runtime"
: "MCP-runtime mediation explicitly OFF ([scope].enforce_runtime = false); remove it to get observe-by-default, or set true to enforce",
category,
};
}
Expand Down
35 changes: 32 additions & 3 deletions src/exec-broker/broker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,48 @@ enforce_runtime = true
assert.equal(ran, false);
});

it("signed scope WITHOUT enforce_runtime → runtime unchanged (falls through to passthrough)", async () => {
it("DEFAULT-ON: a signed scope WITHOUT enforce_runtime observes by default (audits would-deny, never denies)", async () => {
await writeSignedProfile(`version = 1\n[scope]\negress = ["api.acme.com"]\n`, true);
let ran = false;
const out = await runBrokered(
CTX({ egressTargets: ["https://evil.com"] }), // off-scope, but no runtime opt-in → not gated
CTX({ egressTargets: ["https://evil.com"] }), // off-scope: enforce WOULD deny; observe records it
async () => {
ran = true;
return "ok";
},
{ cwd: sandbox },
);
assert.equal(out.ok, true, "a signed scope alone does not gate the MCP runtime");
assert.equal(out.ok, true, "observe-by-default never denies");
assert.equal(ran, true);
const obs = auditLines().find((l) => (l.metadata as { phase?: string })?.phase === "observe");
assert.ok(obs, "default-on mediates in observe → an observe audit entry is written");
const wouldDeny = (obs!.metadata as { wouldDeny?: string[] }).wouldDeny ?? [];
assert.ok(
wouldDeny.some((d) => d.includes("evil.com")),
`the would-be denial is recorded: ${JSON.stringify(wouldDeny)}`,
);
});

it("explicit enforce_runtime = false → runtime OFF (opt out of mediation entirely)", async () => {
await writeSignedProfile(
`version = 1\n[scope]\negress = ["api.acme.com"]\nenforce_runtime = false\n`,
true,
);
let ran = false;
const out = await runBrokered(
CTX({ egressTargets: ["https://evil.com"] }),
async () => {
ran = true;
return "ok";
},
{ cwd: sandbox },
);
assert.equal(out.ok, true);
assert.equal(ran, true);
assert.ok(
!auditLines().some((l) => (l.metadata as { phase?: string })?.phase === "observe"),
"explicit off writes no observe audit entry",
);
});

it("infrastructure op under a restrictive enforce_runtime scope → allowed + audited exemption", async () => {
Expand Down
18 changes: 18 additions & 0 deletions src/exec-broker/profile-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,22 @@ describe("profileBrokerPolicy", () => {
assert.equal(r.runtimeMode, "observe");
assert.equal(r.policy, null, "unsigned → null policy (observe still reports would-denies)");
});

it("DEFAULT-ON: a declared scope with no enforce_runtime defaults to observe", async () => {
writeFileSync(join(proj, PROFILE_FILE), `version = 1\n[scope]\negress = ["h.io"]\n`);
await signProfile(proj);
const r = await profileBrokerPolicy(proj);
assert.equal(
r.runtimeMode,
"observe",
"mediation is on (dry-run) by default for a declared scope",
);
assert.equal(r.enforceRuntime, false, "default-on is observe, not enforce");
});

it("enforce_runtime = false is an explicit opt-out (runtimeMode off)", async () => {
writeFileSync(join(proj, PROFILE_FILE), `version = 1\n[scope]\nenforce_runtime = false\n`);
await signProfile(proj);
assert.equal((await profileBrokerPolicy(proj)).runtimeMode, "off");
});
});
14 changes: 12 additions & 2 deletions src/exec-broker/profile-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,21 @@ interface ScopeShape {
enforce_runtime?: boolean | "observe";
}

/** Map the signed `enforce_runtime` declaration onto the runtime posture. */
/**
* Map the signed `enforce_runtime` declaration onto the runtime posture (Pillar 3 default-on).
* - `"observe"` → dry-run (mediate, audit would-be denials, never deny);
* - `true` → enforce (mediate + deny);
* - `false` → explicit OFF (opt out of runtime mediation entirely);
* - ABSENT → DEFAULT-ON: a declared scope mediates in `observe` by default. Turning mediation
* on by default is safe because observe never denies — nothing an upgrade could break; it only
* starts recording what enforce WOULD block. Enforce-by-default stays an explicit `true` until
* field evidence from observe justifies flipping it.
*/
function runtimeModeOf(scope: ScopeShape): "off" | "observe" | "enforce" {
if (scope.enforce_runtime === "observe") return "observe";
if (scope.enforce_runtime === true) return "enforce";
return "off";
if (scope.enforce_runtime === false) return "off";
return "observe";
}

/** Map a verified profile `[scope]` onto a BrokerPolicy (fs paths resolved against `cwd`). */
Expand Down
7 changes: 4 additions & 3 deletions src/mcp-server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,9 @@ describe("kit_secrets + signed-scope runtime enforcement (MCP-runtime adoption s
}
});

it("without enforce_runtime the runtime is unchanged (write proceeds)", async () => {
// A signed scope that does NOT opt in ⇒ migration passthrough ⇒ secrets still written.
it("default-on (no enforce_runtime) OBSERVES but never denies (write proceeds)", async () => {
// A signed scope that does NOT set the flag ⇒ default-on observe ⇒ would-be denials are audited
// but the write still proceeds (observe never denies), even though .env.local is off the fs scope.
await writeFile(join(tempDir, PROFILE_FILE), `version = 1\n[scope]\nfs = ["src"]\n`);
await signProfile(tempDir);
const { client, cleanup } = await createTestClient();
Expand All @@ -437,7 +438,7 @@ describe("kit_secrets + signed-scope runtime enforcement (MCP-runtime adoption s
assert.equal(
data.ok,
true,
"no enforce_runtime ⇒ not gated even though .env.local is off the fs scope",
"observe-by-default never denies even though .env.local is off the fs scope",
);
assert.ok(data.writtenKeys.includes("APP_KEY"));
} finally {
Expand Down
105 changes: 105 additions & 0 deletions src/skillspector-delegate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
scrubbedEnv,
stage1Args,
normalizeSkillspectorSarif,
runSkillspectorStage1,
LLM_ENV_VARS,
SKILLSPECTOR_SOURCE,
SKILLSPECTOR_BIN,
} from "./skillspector-delegate.js";

// A minimal SkillSpector-style SARIF 2.1.0 log with one HIGH finding.
const SARIF = JSON.stringify({
runs: [
{
tool: {
driver: {
name: "SkillSpector",
rules: [
{
id: "SC4-curl-bash",
properties: { "security-severity": "8.1", tags: ["supply-chain"] },
},
],
},
},
results: [
{
ruleId: "SC4-curl-bash",
level: "error",
message: { text: "pipes curl into bash" },
locations: [
{
physicalLocation: {
artifactLocation: { uri: "install.sh" },
region: { startLine: 3 },
},
},
],
},
],
},
],
});

describe("skillspector delegate — zero-LLM enforcement (no egress)", () => {
it("scrubbedEnv strips every provider API key and SKILLSPECTOR_* var", () => {
const base: NodeJS.ProcessEnv = {
PATH: "/usr/bin",
OPENAI_API_KEY: "sk-should-be-gone",
ANTHROPIC_API_KEY: "sk-ant-gone",
SKILLSPECTOR_PROVIDER: "openai",
SKILLSPECTOR_MODEL: "gpt-5.4",
HOME: "/home/x",
};
const env = scrubbedEnv(base);
assert.equal(env.PATH, "/usr/bin", "innocuous vars survive");
assert.equal(env.HOME, "/home/x");
for (const k of LLM_ENV_VARS) assert.equal(env[k], undefined, `${k} must be stripped`);
assert.equal(env.SKILLSPECTOR_MODEL, undefined, "SKILLSPECTOR_* stripped");
assert.equal(env.SKILLSPECTOR_PROVIDER, "", "provider pinned empty (no network default)");
});

it("does not mutate the passed-in base env", () => {
const base: NodeJS.ProcessEnv = { OPENAI_API_KEY: "sk-x" };
scrubbedEnv(base);
assert.equal(base.OPENAI_API_KEY, "sk-x", "base env untouched");
});

it("stage1Args never contains an LLM/provider flag", () => {
const args = stage1Args("./skill");
assert.deepEqual(args, ["scan", "./skill", "--format", "sarif"]);
assert.ok(!args.some((a) => /llm|provider|model|openai|anthropic/i.test(a)));
});
});

describe("skillspector delegate — SARIF normalization (attributed)", () => {
it("maps SARIF findings to supply-chain kit findings tagged with the source", () => {
const findings = normalizeSkillspectorSarif(SARIF);
assert.equal(findings.length, 1);
const f = findings[0];
assert.equal(f.category, "supply-chain");
assert.equal(f.status, "fail");
assert.equal(f.severity, "high", "CVSS 8.1 → high");
assert.ok(f.name.startsWith(SKILLSPECTOR_SOURCE), `attributed: ${f.name}`);
assert.match(f.detail, /curl into bash/);
assert.match(f.detail, /install\.sh/);
});

it("returns [] for empty or invalid SARIF (never throws)", () => {
assert.deepEqual(normalizeSkillspectorSarif(""), []);
assert.deepEqual(normalizeSkillspectorSarif("not json"), []);
assert.deepEqual(normalizeSkillspectorSarif(JSON.stringify({ runs: [] })), []);
});
});

describe("skillspector delegate — fail-closed when the binary is absent", () => {
it("returns unavailable (not a silent pass) when skillspector is not installed", async () => {
// skillspector is not installed in CI → resolveToolBin returns null.
const r = await runSkillspectorStage1("./skill");
assert.equal(r.status, "unavailable");
if (r.status === "unavailable") assert.match(r.detail, new RegExp(SKILLSPECTOR_BIN));
});
});
Loading
Loading