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
30 changes: 30 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ jobs:

# Stage 1c: Triage new deps on PRs — handled by separate triage-deps.yml workflow

# Stage 1d: GuardDog nightly deep sweep (#205) — behavioral-malware heuristics
# on the direct deps, uncached and with a generous timeout. Too slow
# (~25s/package) for the local check budget, so the continuous deep scan lives
# here; local `kit check` uses the clean-verdict cache.
guarddog-nightly:
name: Stage 1d — GuardDog malware sweep (nightly)
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: "22"
cache: "npm"
- run: npm ci
- name: Build CLI
run: npm run build
- name: Install guarddog + semgrep
run: pip install --user pipx && pipx install guarddog && pipx install semgrep
- name: GuardDog verify (direct deps, no cache, long budget)
env:
KIT_GUARDDOG: "1"
# 45 min — the sweep is the slow path by design; fail closed on timeout.
KIT_GUARDDOG_TIMEOUT_MS: "2700000"
# Fresh cache path so the sweep never reads a stale verdict — it always
# performs the real scan.
KIT_GUARDDOG_CACHE: "/tmp/guarddog-nightly-cache.json"
run: node scripts/run-guarddog-check.mjs
timeout-minutes: 50

# Stage 2: SAST (ESLint security + semgrep + SonarCloud)
sast:
name: Stage 2 — SAST
Expand Down
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,65 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

## [4.3.0] - 2026-07-07

### Fixed — dogfood findings from real projects (a Turborepo + a Firebase repo)

- **Monorepo workspace resolution (#249).** `kit review`'s source-rooted checks
(test coverage, a11y/design scan) said "no src/ found" in a Turborepo full of
tsx under `apps/*`/`packages/*` — an empty green. New `src/workspaces.ts`
resolves workspaces from `package.json` + `pnpm-workspace.yaml`; both checks
scan each workspace's src dirs, and an empty scan is an explicit monorepo-aware
skip — scanned-zero-files can never read as scanned-clean.
- **Public-by-design client keys get truthful advice (#250).** A Firebase
web-config apiKey was flagged "leaked secret — rotate". The secrets scan now
classifies public-by-design shapes (Firebase web config with co-occurring
authDomain/projectId context, Sentry DSN, PostHog project key) and says
"verify API-key restrictions + security rules" instead. Conservative: no
context or unreadable file keeps the finding; a VERIFIED-LIVE credential is
never waved through.
- **Active gcloud context is cross-checked against the repo's own projects
(#251).** `kit init` captured another customer's ACTIVE gcloud project into a
repo whose `.firebaserc` names its own. The context-lock offer now warns with
both values named and suggests the repo's project; `kit context check` flags
the mismatch (exit 1) even with no `[context]` declared.

### Changed — guarddog that can actually finish (#205)

- **Direct-deps target + clean-verdict cache + nightly sweep.** guarddog costs
~25s/package, so verifying a 12k-package lockfile always timed out into
UNVERIFIED. It now verifies `package.json` (direct deps — guarddog's depth;
the full tree keeps bumblebee + osv breadth), caches only COMPLETE clean
verdicts keyed by a direct-deps hash (`~/.kit/guarddog-cache.json`; hits say
the verdict date, never pretend to have just scanned), and a nightly
fail-closed `guarddog-nightly` job in security.yml runs the uncached sweep
with a 45-minute budget. `KIT_GUARDDOG_TIMEOUT_MS` overrides the local 300s.

### Added — evidence + memory reach

- **`kit coverage --verify` binds more evidence without a false-green shortcut
(#206).** Self-audit results carry their stable `ruleId`; coverage binds by
name OR rule id, resolves a curated alias map (broad category matching was
deliberately rejected — it would let any passing category-mate "verify"
unrelated controls), and runs the cheap command-backed evidence inline
(gha-audit/ci-audit, transcript scan). On kit: 4 not-run → 1 (only the
vault-backed secrets validation stays honestly unbound).
- **`kit memory merge --remap-project` + loud foreign-scope summary (#247).**
A merged session keyed to another machine's path (a container's `-home-user`)
is invisible to project-scoped search — "merged" must not read as "reachable".
The merge now reports where sessions landed and points to `--remap-project` /
`--global`; re-merging with the flag rehomes an already-imported session.

### Security — semgrep p/default: 31 findings → 0 (sec-09ef20)

- Pinned `actions/checkout@v4` + `actions/setup-node@v4` to commit SHAs in
kit's own action and shipped templates (kit's gha-audit rule, applied to
kit's own house).
- docker-compose: `no-new-privileges` + read-only root fs on postgres/redis.
- Escaped a key interpolated into a regex in the one builder that predated the
escapeRegex convention; remaining regexp/formatstring findings suppressed
per-site with justification (escaped internal identifiers, module constants).

## [4.2.0] - 2026-07-06

### Security — surface a trust-bearing KIT_DEVICE_ID override (#79)
Expand Down
2 changes: 1 addition & 1 deletion action/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ runs:
using: "composite"
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: "22"

Expand Down
14 changes: 13 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.8'
version: "3.8"

services:
# kit CLI - for testing CLI commands
Expand Down Expand Up @@ -47,6 +47,15 @@ services:
postgres:
image: postgres:16-alpine
container_name: kit-postgres
# Hardening (semgrep no-new-privileges / writable-filesystem): no setuid
# escalation; root fs read-only — postgres writes only via the data volume
# and the tmpfs run/tmp dirs.
security_opt:
- no-new-privileges:true
read_only: true
tmpfs:
- /tmp
- /run/postgresql
environment:
POSTGRES_USER: kit
POSTGRES_PASSWORD: password
Expand All @@ -68,6 +77,9 @@ services:
redis:
image: redis:7-alpine
container_name: kit-redis
security_opt:
- no-new-privileges:true
read_only: true
ports:
- "6379:6379"
volumes:
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": "4.2.0",
"version": "4.3.0",
"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
29 changes: 29 additions & 0 deletions scripts/run-guarddog-check.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node
// Nightly GuardDog sweep (#205): run ONLY the guarddog malware check, uncached,
// with the generous CI budget (KIT_GUARDDOG_TIMEOUT_MS). Fail closed: in the
// nightly sweep an UNVERIFIED/incomplete scan blocks — the sweep exists to
// guarantee a completed scan happens continuously, so "didn't finish" is a
// failure here, not a warning.
import { checkSecurity } from "../dist/check-security.js";

const all = await checkSecurity();
const guarddog = all.filter((r) => r.name === "guarddog (malware)");

console.log(JSON.stringify(guarddog, null, 2));

if (guarddog.length === 0) {
console.error("FAIL: guarddog check did not run at all (opt-in env missing?)");
process.exit(1);
}
const blocking = guarddog.filter((r) => r.status === "fail" || r.status === "warn");
if (blocking.length > 0) {
console.error(`\nFAIL: guarddog sweep blocked:`);
for (const f of blocking) console.error(` - ${f.name} [${f.status}]: ${f.detail}`);
process.exit(1);
}
const skipped = guarddog.filter((r) => r.status === "skip");
if (skipped.length === guarddog.length) {
console.error("FAIL: guarddog sweep skipped — nothing was scanned (fail-closed in nightly)");
process.exit(1);
}
console.log(`\nPASS: guarddog sweep clean (${guarddog.length} result(s))`);
12 changes: 8 additions & 4 deletions src/check-design.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import { readFile, access } from "node:fs/promises";
import { resolve, relative } from "node:path";
import { walkSourceFiles } from "./source-walk.js";
import { workspaceSourceDirs } from "./workspaces.js";

export interface DesignCheckResult {
category: "design";
Expand Down Expand Up @@ -171,9 +172,11 @@ export async function checkDesign(
baseline?: { a11y?: string[]; tokens?: string[] };
} = {},
): Promise<DesignCheckResult[]> {
const srcRoots = (opts.srcRoots ?? ["src", "app", "components"]).map((d) =>
resolve(process.cwd(), d),
);
// Monorepo (#249): also scan each workspace's src/app/components — a Turborepo
// full of tsx under apps/* must not read as "no components found".
const rootDirs = opts.srcRoots ?? ["src", "app", "components"];
const wsDirs = opts.srcRoots ? [] : workspaceSourceDirs(process.cwd(), rootDirs);
const srcRoots = [...rootDirs, ...wsDirs].map((d) => resolve(process.cwd(), d));
const tokenFiles = opts.tokenFiles ?? ["design-tokens", "tokens.ts", "theme.ts"];
const enforce = opts.enforce ?? false;
const results: DesignCheckResult[] = [];
Expand All @@ -196,7 +199,8 @@ export async function checkDesign(
category: "design",
name: "a11y (static scan)",
status: "skip",
detail: "no tsx/jsx/astro/vue files found",
detail:
"no tsx/jsx/astro/vue files found (root + workspace src dirs) — if this is a monorepo, workspace resolution may have missed them",
});
return results;
}
Expand Down
61 changes: 57 additions & 4 deletions src/check-security.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ describe("findJvmProject (#110 — Gradle + nested depth)", () => {
});
});

describe("classifyTrufflehogFindings (verified vs unverified)", () => {
describe("classifyTrufflehogFindings (verified vs unverified vs public-by-design)", () => {
const line = (det: string, verified: boolean) =>
JSON.stringify({ DetectorName: det, Verified: verified });

it("ignores the trufflehog info log line (no DetectorName)", () => {
const out = classifyTrufflehogFindings('{"level":"info","msg":"starting"}\n');
assert.deepStrictEqual(out, { verified: 0, unverified: 0 });
assert.deepStrictEqual(out, { verified: 0, unverified: 0, publicByDesign: 0 });
});

it("splits verified-live from unverified findings", () => {
Expand All @@ -218,12 +218,65 @@ describe("classifyTrufflehogFindings (verified vs unverified)", () => {
line("Postgres", false),
line("AWS", true),
].join("\n");
assert.deepStrictEqual(classifyTrufflehogFindings(stdout), { verified: 1, unverified: 2 });
assert.deepStrictEqual(classifyTrufflehogFindings(stdout), {
verified: 1,
unverified: 2,
publicByDesign: 0,
});
});

it("counts an unparseable DetectorName line conservatively as unverified", () => {
const out = classifyTrufflehogFindings('{"DetectorName":"X" broken json');
assert.deepStrictEqual(out, { verified: 0, unverified: 1 });
assert.deepStrictEqual(out, { verified: 0, unverified: 1, publicByDesign: 0 });
});
});

describe("public-by-design client keys (#250)", () => {
const AIZA = "AIza" + "A".repeat(35);
const fbLine = JSON.stringify({
DetectorName: "GoogleApiKey",
Verified: false,
Raw: AIZA,
SourceMetadata: { Data: { Git: { file: "src/firebase.ts" } } },
});
const fbConfig = `export const firebaseConfig = { apiKey: "${AIZA}", authDomain: "x.firebaseapp.com", projectId: "x" }`;

it("Firebase web config = public-by-design ONLY with co-occurring config context", () => {
const withContext = classifyTrufflehogFindings(fbLine, () => fbConfig);
assert.deepStrictEqual(withContext, { verified: 0, unverified: 0, publicByDesign: 1 });
// Same AIza key WITHOUT Firebase context could be a privileged server key —
// stays a normal unverified finding.
const without = classifyTrufflehogFindings(fbLine, () => `const key = "${AIZA}"`);
assert.deepStrictEqual(without, { verified: 0, unverified: 1, publicByDesign: 0 });
// Unreadable/deleted file ⇒ never downgrade on missing evidence.
const unreadable = classifyTrufflehogFindings(fbLine, () => null);
assert.deepStrictEqual(unreadable, { verified: 0, unverified: 1, publicByDesign: 0 });
});

it("a VERIFIED-LIVE AIza key is never waved through as public-by-design", () => {
const liveLine = JSON.stringify({
DetectorName: "GoogleApiKey",
Verified: true,
Raw: AIZA,
SourceMetadata: { Data: { Git: { file: "src/firebase.ts" } } },
});
const out = classifyTrufflehogFindings(liveLine, () => fbConfig);
assert.deepStrictEqual(out, { verified: 1, unverified: 0, publicByDesign: 0 });
});

it("Sentry DSN and PostHog project keys are public-by-design by shape alone", () => {
const dsn = JSON.stringify({
DetectorName: "SentryDSN",
Verified: false,
Raw: "https://abcdef0123456789@o123.ingest.sentry.io/456",
});
const phc = JSON.stringify({
DetectorName: "Generic",
Verified: false,
Raw: "phc_" + "a".repeat(43),
});
const out = classifyTrufflehogFindings([dsn, phc].join("\n"), () => null);
assert.deepStrictEqual(out, { verified: 0, unverified: 0, publicByDesign: 2 });
});
});

Expand Down
Loading
Loading