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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

## [1.17.0] - 2026-06-23

### Added
- **Install-time supply-chain triage (`kit supply-chain`).** Four deterministic, local-first checks over `package.json` + `package-lock.json` (no network, no node_modules walk): **install-scripts** (deps that run pre/post/install — the malware-execution vector, from the lockfile's `hasInstallScript`), **lockfile-drift** (declared deps missing from the lockfile + packages resolved from a non-registry http/git source), **dep-confusion** (a dep under a declared `[supply_chain] internal_scopes` entry that the lockfile resolves from the PUBLIC registry), and **slopsquat** (a dep name ≤1 Damerau-Levenshtein edit — incl. transposition, e.g. `lodahs`→`lodash` — from a bundled high-traffic-package corpus). Pure check functions are fixture-tested; the typosquat corpus is local and curated. (#49)

## [1.16.0] - 2026-06-23

### 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.16.0",
"version": "1.17.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
27 changes: 27 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4167,6 +4167,32 @@ async function cmdIngest(): Promise<boolean> {
return true;
}

async function cmdSupplyChain(): Promise<boolean> {
const jsonMode = hasFlag(process.argv, "--json");
const config = await loadConfig(resolveConfigPath());
const scopes = config.supply_chain?.internal_scopes ?? [];
const { runSupplyChain } = await import("./supply-chain.js");
const results = runSupplyChain(process.cwd(), scopes);
const fails = results.filter((r) => r.status === "fail").length;

if (jsonMode) {
console.log(JSON.stringify({ ok: fails === 0, results }, null, 2));
return fails === 0;
}

console.log(`${c.bold}kit supply-chain${c.reset}`);
for (const r of results) {
const mark =
r.status === "fail" ? `${c.red}✗${c.reset}` :
r.status === "warn" ? `${c.yellow}!${c.reset}` :
r.status === "skip" ? `${c.dim}−${c.reset}` : `${c.green}✓${c.reset}`;
console.log(` ${mark} ${r.name} ${c.dim}${r.detail}${c.reset}`);
if (r.suggestion) console.log(` ${c.dim}${r.suggestion}${c.reset}`);
}
if (fails > 0) console.log(`${c.red}${fails} fail${c.reset}`);
return fails === 0;
}

async function cmdWhoami(): Promise<boolean> {
const jsonMode = hasFlag(process.argv, "--json");

Expand Down Expand Up @@ -4906,6 +4932,7 @@ async function main(): Promise<void> {
check: cmdCheck,
health: cmdHealth,
ingest: cmdIngest,
"supply-chain": cmdSupplyChain,
init: cmdInit,
upgrade: cmdUpgrade,
install: cmdInstall,
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ export interface kitConfig {
hooks?: HooksConfig;
/** Per-project CLI context lock (account+project per tool). */
context?: ContextConfig;
/** Install-time supply-chain triage settings (`kit supply-chain`). */
supply_chain?: { internal_scopes?: string[] };
web?: {
search?: WebSearchConfig;
};
Expand Down Expand Up @@ -538,6 +540,10 @@ const kitConfigSchema = z
})
.passthrough()
.optional(),
supply_chain: z
.object({ internal_scopes: z.array(z.string()).optional() })
.passthrough()
.optional(),
web: WebConfigSchema,
setup: z
.object({
Expand Down
24 changes: 24 additions & 0 deletions src/data/top-npm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* A curated set of high-traffic npm package names, used as the typosquat/slopsquat
* reference corpus: a dependency that is edit-distance ≤1 from one of these but not
* an exact match is a likely look-alike. Kept deliberately small and local (no
* network) — it covers the names attackers most often imitate, not all of npm.
*/
export const TOP_NPM: readonly string[] = [
"react", "react-dom", "lodash", "express", "axios", "chalk", "commander",
"debug", "moment", "request", "async", "bluebird", "underscore", "yargs",
"uuid", "glob", "minimist", "semver", "rimraf", "mkdirp", "dotenv", "cors",
"body-parser", "webpack", "babel-core", "typescript", "eslint", "prettier",
"jest", "mocha", "chai", "vue", "angular", "next", "vite", "rollup", "ws",
"node-fetch", "cross-env", "nodemon", "ts-node", "tslib", "zod", "prisma",
"redux", "react-redux", "styled-components", "tailwindcss", "postcss",
"classnames", "immer", "rxjs", "graphql", "apollo-server", "mongoose",
"sequelize", "pg", "mysql2", "redis", "ioredis", "socket.io", "passport",
"jsonwebtoken", "bcrypt", "bcryptjs", "helmet", "morgan", "winston", "pino",
"nanoid", "date-fns", "dayjs", "ramda", "fastify", "koa", "ejs", "handlebars",
"sharp", "puppeteer", "playwright", "cheerio", "form-data", "qs", "ini",
"colors", "inquirer", "ora", "execa", "fs-extra", "globby", "chokidar",
"esbuild", "terser", "core-js", "regenerator-runtime", "left-pad",
];

export const TOP_NPM_SET: ReadonlySet<string> = new Set(TOP_NPM);
83 changes: 83 additions & 0 deletions src/supply-chain.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";
import {
findInstallScripts,
findLockDrift,
findNonRegistryResolved,
findDepConfusion,
editDistance,
findSlopsquat,
parseLockPkgs,
type LockPkg,
} from "./supply-chain.js";

const lockPkgs: LockPkg[] = [
{ path: "node_modules/lodash", name: "lodash", version: "4.17.21", resolved: "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz" },
{ path: "node_modules/esbuild", name: "esbuild", version: "0.20.0", resolved: "https://registry.npmjs.org/esbuild/-/esbuild-0.20.0.tgz", hasInstallScript: true },
{ path: "node_modules/sketchy", name: "sketchy", version: "1.0.0", resolved: "https://evil.example/sketchy.tgz" },
{ path: "node_modules/@acme/core", name: "@acme/core", version: "2.0.0", resolved: "https://registry.npmjs.org/@acme/core/-/core-2.0.0.tgz" },
];

describe("findInstallScripts", () => {
it("flags only packages with hasInstallScript", () => {
assert.deepEqual(findInstallScripts(lockPkgs), ["esbuild@0.20.0"]);
});
});

describe("findLockDrift", () => {
it("flags declared deps absent from the lockfile", () => {
const lockNames = new Set(lockPkgs.map((p) => p.name));
assert.deepEqual(findLockDrift(["lodash", "ghost-dep"], lockNames), ["ghost-dep"]);
});
});

describe("findNonRegistryResolved", () => {
it("flags http/git tarball sources, not registry ones", () => {
const bad = findNonRegistryResolved(lockPkgs);
assert.equal(bad.length, 1);
assert.equal(bad[0].name, "sketchy");
});
});

describe("findDepConfusion", () => {
const resolved = new Map(lockPkgs.map((p) => [p.name, p.resolved] as const));
it("flags an internal-scoped dep resolved from the public registry", () => {
assert.deepEqual(findDepConfusion(["@acme/core"], resolved, ["@acme"]), ["@acme/core"]);
});
it("is empty when no internal scopes are declared", () => {
assert.deepEqual(findDepConfusion(["@acme/core"], resolved, []), []);
});
it("does not flag a scope substring match (@acme vs @acme-tools)", () => {
const r = new Map([["@acme-tools/x", "https://registry.npmjs.org/x"] as const]);
assert.deepEqual(findDepConfusion(["@acme-tools/x"], r, ["@acme"]), []);
});
});

describe("editDistance (bounded Damerau)", () => {
it("treats a transposition as a single edit, plus subs/inserts/deletes, and caps", () => {
assert.equal(editDistance("lodash", "lodash"), 0);
assert.equal(editDistance("lodash", "lodahs"), 1); // adjacent transposition
assert.equal(editDistance("react", "preact"), 1); // insertion
assert.equal(editDistance("abc", "xyzzy", 2), 3); // exceeds cap
});
});

describe("findSlopsquat", () => {
it("flags a 1-edit look-alike of a popular package", () => {
const hits = findSlopsquat(["lodahs", "expres"]); // lodash, express look-alikes
const names = hits.map((h) => h.name);
assert.ok(names.includes("lodahs"));
assert.ok(names.includes("expres"));
});
it("does not flag exact popular packages or distant names", () => {
assert.deepEqual(findSlopsquat(["lodash", "my-unique-internal-pkg"]), []);
});
});

describe("parseLockPkgs", () => {
it("skips the root entry and flattens packages", () => {
const pkgs = parseLockPkgs({ packages: { "": { name: "root" }, "node_modules/x": { version: "1.0.0", resolved: "r" } } });
assert.equal(pkgs.length, 1);
assert.equal(pkgs[0].name, "x");
});
});
Loading
Loading