coldpin 0.0.0-stage → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ACCESSIBILITY.md +17 -0
- package/CHANGELOG.md +89 -0
- package/CONTRIBUTING.md +36 -0
- package/LICENSE +98 -0
- package/MAINTENANCE.md +33 -0
- package/README.md +142 -2
- package/SECURITY.md +34 -0
- package/TESTING.md +26 -0
- package/agents/coldpin-auditor.md +47 -0
- package/agents/coldpin-compliance.md +38 -0
- package/agents/coldpin-confusion-auditor.md +38 -0
- package/agents/coldpin-discoverer.md +37 -0
- package/agents/coldpin-forensics.md +38 -0
- package/agents/coldpin-inspector.md +37 -0
- package/agents/coldpin-manifest-auditor.md +38 -0
- package/assets/icon.svg +7 -0
- package/catalog/mcp-schema-pin.json +14 -0
- package/catalog/plugin.oms.sig +19 -0
- package/catalog/sigma/npx-suspicious-child-process-linux.yml +54 -0
- package/catalog/sigma/npx-suspicious-child-process.yml +49 -0
- package/catalog/triage-rules.json +104 -0
- package/docs/assets/readme-header.svg +21 -0
- package/docs/designs/SITEMAP.md +14 -0
- package/docs/designs/coldpin.md +68 -0
- package/docs/fact-ledger.md +35 -0
- package/docs/faq.md +31 -0
- package/docs/getting_started.md +62 -0
- package/docs/harnesses.md +45 -0
- package/docs/privacy.md +27 -0
- package/docs/verification/skill-inspector-self-audit.md +33 -0
- package/examples/.coldpin.policy.example.json +27 -0
- package/examples/.npmrc.example +8 -0
- package/examples/mcp_config.private-registry.example.json +42 -0
- package/hooks.json +47 -0
- package/lib/analysis/parity-and-bisect.mjs +1371 -0
- package/lib/analysis/static-triage.mjs +4572 -0
- package/lib/cache/sqlite-store.mjs +251 -0
- package/lib/cli.mjs +427 -0
- package/lib/compliance/audit-log.mjs +357 -0
- package/lib/config/policy.mjs +780 -0
- package/lib/core/path-confinement.mjs +289 -0
- package/lib/core/workflows.mjs +1205 -0
- package/lib/discovery/slopsquat-guard.mjs +289 -0
- package/lib/hook.mjs +1038 -0
- package/lib/intel/registry-osv.mjs +1681 -0
- package/lib/mcp/report-store.mjs +175 -0
- package/lib/mcp/server.mjs +1387 -0
- package/lib/mcp/stdio-transport.mjs +289 -0
- package/lib/mcp/tool-catalog.mjs +273 -0
- package/lib/mcp/types.mjs +95 -0
- package/lib/mcp.mjs +19 -0
- package/lib/quarantine/safe-unpack.mjs +568 -0
- package/lib/types.mjs +383 -0
- package/lib/verdict/engine-and-formatters.mjs +895 -0
- package/mcp_config.json +21 -0
- package/package.json +71 -3
- package/plugin.json +54 -0
- package/rules/AGENTS.md +18 -0
- package/rules/coldpin-incident-checklist.md +18 -0
- package/rules/coldpin-manifest-guard.md +14 -0
- package/server.json +38 -0
- package/skills/coldpin/BENCHMARK.md +166 -0
- package/skills/coldpin/SKILL.md +110 -0
- package/skills/coldpin/TEST.md +13 -0
- package/skills/coldpin/agents/openai.yaml +6 -0
- package/skills/coldpin/assets/icon.svg +7 -0
- package/skills/coldpin/assets/runtime-contract.yaml +105 -0
- package/skills/coldpin/evals/evals.json +60 -0
- package/skills/coldpin/references/aspect-compliance-audit.md +27 -0
- package/skills/coldpin/references/aspect-discovery.md +26 -0
- package/skills/coldpin/references/aspect-forensics-rea.md +26 -0
- package/skills/coldpin/references/aspect-inspection.md +26 -0
- package/skills/coldpin/references/aspect-manifest-confusion.md +26 -0
- package/skills/coldpin/references/enterprise-policy-schema.md +65 -0
- package/skills/coldpin/references/evidence-card-spec.md +27 -0
- package/skills/coldpin/references/rea-integration-playbook.md +34 -0
- package/skills/coldpin/references/threat-taxonomy.md +35 -0
- package/skills/coldpin/skill-card.md +62 -0
- package/skills/coldpin/skill.oms.sig +19 -0
- package/skills/coldpin/test_scenarios.yaml +61 -0
- package/skills/coldpin-audit/SKILL.md +39 -0
- package/skills/coldpin-incident/SKILL.md +37 -0
- package/src/analysis/parity-and-bisect.ts +1368 -0
- package/src/analysis/static-triage.ts +4569 -0
- package/src/cache/sqlite-store.ts +248 -0
- package/src/cli.ts +424 -0
- package/src/compliance/audit-log.ts +354 -0
- package/src/config/policy.ts +777 -0
- package/src/core/path-confinement.ts +286 -0
- package/src/core/workflows.ts +1202 -0
- package/src/discovery/slopsquat-guard.ts +286 -0
- package/src/hook.ts +1035 -0
- package/src/intel/registry-osv.ts +1678 -0
- package/src/mcp/report-store.ts +172 -0
- package/src/mcp/server.ts +1384 -0
- package/src/mcp/stdio-transport.ts +286 -0
- package/src/mcp/tool-catalog.ts +270 -0
- package/src/mcp/types.ts +92 -0
- package/src/mcp.ts +16 -0
- package/src/quarantine/safe-unpack.ts +565 -0
- package/src/types.ts +380 -0
- package/src/verdict/engine-and-formatters.ts +892 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { levenshtein } from "../config/policy.ts";
|
|
2
|
+
import type { Observation, PolicyConfig } from "../types.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* High-value npm CLI & core ecosystem target corpus for offline 7-primitive typosquat screening.
|
|
6
|
+
* Kept intentionally focused on high-target npx CLIs and core libraries to prevent false positives.
|
|
7
|
+
*/
|
|
8
|
+
export const TOP_NPM_TARGETS: readonly string[] = [
|
|
9
|
+
"eslint",
|
|
10
|
+
"prettier",
|
|
11
|
+
"typescript",
|
|
12
|
+
"create-react-app",
|
|
13
|
+
"create-next-app",
|
|
14
|
+
"create-vite",
|
|
15
|
+
"create-astro",
|
|
16
|
+
"create-svelte",
|
|
17
|
+
"cross-env",
|
|
18
|
+
"nodemon",
|
|
19
|
+
"concurrently",
|
|
20
|
+
"rimraf",
|
|
21
|
+
"http-server",
|
|
22
|
+
"live-server",
|
|
23
|
+
"serve",
|
|
24
|
+
"ngrok",
|
|
25
|
+
"playwright",
|
|
26
|
+
"cypress",
|
|
27
|
+
"vitest",
|
|
28
|
+
"jest",
|
|
29
|
+
"mocha",
|
|
30
|
+
"webpack",
|
|
31
|
+
"esbuild",
|
|
32
|
+
"rollup",
|
|
33
|
+
"parcel",
|
|
34
|
+
"turbo",
|
|
35
|
+
"nx",
|
|
36
|
+
"lerna",
|
|
37
|
+
"changesets",
|
|
38
|
+
"semantic-release",
|
|
39
|
+
"husky",
|
|
40
|
+
"lint-staged",
|
|
41
|
+
"commitlint",
|
|
42
|
+
"storybook",
|
|
43
|
+
"prisma",
|
|
44
|
+
"drizzle-kit",
|
|
45
|
+
"supabase",
|
|
46
|
+
"firebase-tools",
|
|
47
|
+
"wrangler",
|
|
48
|
+
"vercel",
|
|
49
|
+
"netlify-cli",
|
|
50
|
+
"aws-cdk",
|
|
51
|
+
"serverless",
|
|
52
|
+
"tailwindcss",
|
|
53
|
+
"postcss",
|
|
54
|
+
"autoprefixer",
|
|
55
|
+
"shadcn",
|
|
56
|
+
"degit",
|
|
57
|
+
"tiged",
|
|
58
|
+
"taze",
|
|
59
|
+
"npm-check-updates",
|
|
60
|
+
"depcheck",
|
|
61
|
+
"madge",
|
|
62
|
+
"knip",
|
|
63
|
+
"biome",
|
|
64
|
+
"oxlint",
|
|
65
|
+
"tsx",
|
|
66
|
+
"ts-node",
|
|
67
|
+
"lodash",
|
|
68
|
+
"axios",
|
|
69
|
+
"express",
|
|
70
|
+
"commander",
|
|
71
|
+
"yargs",
|
|
72
|
+
"inquirer",
|
|
73
|
+
"chalk",
|
|
74
|
+
"ora",
|
|
75
|
+
"dotenv",
|
|
76
|
+
"semver",
|
|
77
|
+
"uuid",
|
|
78
|
+
"zod",
|
|
79
|
+
"react",
|
|
80
|
+
"next",
|
|
81
|
+
"vite",
|
|
82
|
+
"astro",
|
|
83
|
+
"svelte",
|
|
84
|
+
"vue",
|
|
85
|
+
"angular",
|
|
86
|
+
"electron",
|
|
87
|
+
"puppeteer",
|
|
88
|
+
"sharp",
|
|
89
|
+
"bcrypt",
|
|
90
|
+
"jsonwebtoken",
|
|
91
|
+
"mongoose",
|
|
92
|
+
"sequelize",
|
|
93
|
+
"typeorm",
|
|
94
|
+
"socket.io",
|
|
95
|
+
"graphql",
|
|
96
|
+
"apollo",
|
|
97
|
+
"trpc",
|
|
98
|
+
"hono",
|
|
99
|
+
"fastify",
|
|
100
|
+
"koa",
|
|
101
|
+
"nestjs",
|
|
102
|
+
"renovate",
|
|
103
|
+
"snyk",
|
|
104
|
+
"trivy",
|
|
105
|
+
"rea-agents",
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
const HOMOGLYPH_MAP: Record<string, string> = {
|
|
109
|
+
"0": "o",
|
|
110
|
+
"1": "l",
|
|
111
|
+
"3": "e",
|
|
112
|
+
"4": "a",
|
|
113
|
+
"5": "s",
|
|
114
|
+
"7": "t",
|
|
115
|
+
rn: "m",
|
|
116
|
+
vv: "w",
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function normalizeHomoglyphs(name: string): string {
|
|
120
|
+
let out = name.toLowerCase();
|
|
121
|
+
for (const [k, v] of Object.entries(HOMOGLYPH_MAP)) {
|
|
122
|
+
out = out.replaceAll(k, v);
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function stripDelimiters(name: string): string {
|
|
128
|
+
return name.toLowerCase().replace(/[-_.]/g, "");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function sortedTokens(name: string): string {
|
|
132
|
+
return name
|
|
133
|
+
.toLowerCase()
|
|
134
|
+
.split(/[-_.]/)
|
|
135
|
+
.filter(Boolean)
|
|
136
|
+
.sort()
|
|
137
|
+
.join("-");
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function stripCommonSuffix(name: string): string {
|
|
141
|
+
return name.toLowerCase().replace(/-(js|ts|cli|node|npm|pkg|official|lib)$/, "");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isSingleTransposition(a: string, b: string): boolean {
|
|
145
|
+
if (a.length !== b.length || a.length < 3) return false;
|
|
146
|
+
const diffs: number[] = [];
|
|
147
|
+
for (let i = 0; i < a.length; i++) {
|
|
148
|
+
if (a[i] !== b[i]) diffs.push(i);
|
|
149
|
+
if (diffs.length > 2) return false;
|
|
150
|
+
}
|
|
151
|
+
if (diffs.length !== 2) return false;
|
|
152
|
+
const i0 = diffs[0]!;
|
|
153
|
+
const i1 = diffs[1]!;
|
|
154
|
+
return i1 === i0 + 1 && a[i0] === b[i1] && a[i1] === b[i0];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface SquatMatch {
|
|
158
|
+
target: string;
|
|
159
|
+
primitive:
|
|
160
|
+
| "transposition"
|
|
161
|
+
| "omission_or_repetition"
|
|
162
|
+
| "delimiter_swap"
|
|
163
|
+
| "word_order"
|
|
164
|
+
| "homoglyph"
|
|
165
|
+
| "suffix_brandjack";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Checks a candidate npm package name against all 7 canonical typosquatting primitives
|
|
170
|
+
* while suppressing false positives on short names (< 5 chars).
|
|
171
|
+
*/
|
|
172
|
+
export function detectTyposquatPrimitives(
|
|
173
|
+
rawPackageName: string,
|
|
174
|
+
corpus: readonly string[] = TOP_NPM_TARGETS,
|
|
175
|
+
): SquatMatch | null {
|
|
176
|
+
// Strip @scope/ for bare-name comparison, unless exact scoped match is checked separately
|
|
177
|
+
const bare = rawPackageName.includes("/")
|
|
178
|
+
? rawPackageName.slice(rawPackageName.indexOf("/") + 1).toLowerCase()
|
|
179
|
+
: rawPackageName.toLowerCase();
|
|
180
|
+
|
|
181
|
+
// Minimum length guard prevents flagging legitimate short CLIs (tsx, zx, vit, bun)
|
|
182
|
+
if (bare.length < 5) return null;
|
|
183
|
+
|
|
184
|
+
const corpusSet = new Set(corpus.map((c) => c.toLowerCase()));
|
|
185
|
+
if (corpusSet.has(bare)) return null;
|
|
186
|
+
|
|
187
|
+
const bareNoDelim = stripDelimiters(bare);
|
|
188
|
+
const bareSorted = sortedTokens(bare);
|
|
189
|
+
const bareHomoglyph = normalizeHomoglyphs(bare);
|
|
190
|
+
const bareNoSuffix = stripCommonSuffix(bare);
|
|
191
|
+
|
|
192
|
+
for (const target of corpus) {
|
|
193
|
+
const t = target.toLowerCase();
|
|
194
|
+
if (t.length < 5 || bare === t) continue;
|
|
195
|
+
|
|
196
|
+
// 1. Transposition (e.g. reqeusts -> requests, loadsh -> lodash)
|
|
197
|
+
if (isSingleTransposition(bare, t)) {
|
|
198
|
+
return { target: t, primitive: "transposition" };
|
|
199
|
+
}
|
|
200
|
+
// 2. Delimiter swap (e.g. crossenv -> cross-env, create_react_app -> create-react-app)
|
|
201
|
+
if (bareNoDelim === stripDelimiters(t) && bare !== t) {
|
|
202
|
+
return { target: t, primitive: "delimiter_swap" };
|
|
203
|
+
}
|
|
204
|
+
// 3. Word order swap (e.g. env-cross -> cross-env, server-http -> http-server)
|
|
205
|
+
if (bare.includes("-") && t.includes("-") && bareSorted === sortedTokens(t) && bare !== t) {
|
|
206
|
+
return { target: t, primitive: "word_order" };
|
|
207
|
+
}
|
|
208
|
+
// 4. Homoglyph substitution (e.g. es1int -> eslint, pr3ttier -> prettier)
|
|
209
|
+
if (bareHomoglyph === normalizeHomoglyphs(t) && bare !== t) {
|
|
210
|
+
return { target: t, primitive: "homoglyph" };
|
|
211
|
+
}
|
|
212
|
+
// 5. Suffix / brandjacking (e.g. lodash-js, eslint-official, prettier-cli)
|
|
213
|
+
if (bareNoSuffix === t && bare !== t) {
|
|
214
|
+
return { target: t, primitive: "suffix_brandjack" };
|
|
215
|
+
}
|
|
216
|
+
// 6 & 7. Omission / Repetition / 1-edit substitution (Levenshtein == 1)
|
|
217
|
+
if (levenshtein(bare, t) === 1) {
|
|
218
|
+
return { target: t, primitive: "omission_or_repetition" };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function evaluateSlopsquatAndCooldown(params: {
|
|
226
|
+
package_name: string;
|
|
227
|
+
created_at_iso?: string;
|
|
228
|
+
version_published_at_iso?: string;
|
|
229
|
+
weekly_downloads?: number;
|
|
230
|
+
has_lifecycle_scripts: boolean;
|
|
231
|
+
policy: PolicyConfig;
|
|
232
|
+
now_ms?: number;
|
|
233
|
+
}): Observation[] {
|
|
234
|
+
const obs: Observation[] = [];
|
|
235
|
+
const now = params.now_ms ?? Date.now();
|
|
236
|
+
|
|
237
|
+
const squat = detectTyposquatPrimitives(params.package_name);
|
|
238
|
+
if (squat) {
|
|
239
|
+
const lowDownloads = params.weekly_downloads !== undefined && params.weekly_downloads < 1000;
|
|
240
|
+
const isYoung =
|
|
241
|
+
params.created_at_iso !== undefined &&
|
|
242
|
+
now - Date.parse(params.created_at_iso) < 90 * 24 * 3600 * 1000;
|
|
243
|
+
const severity = lowDownloads || isYoung || params.has_lifecycle_scripts ? "CRITICAL" : "HIGH";
|
|
244
|
+
obs.push({
|
|
245
|
+
code: "TYPOSQUAT_OR_SLOPSQUAT_MATCH",
|
|
246
|
+
severity,
|
|
247
|
+
path: "<registry-metadata>",
|
|
248
|
+
attack_id: "T1195.002",
|
|
249
|
+
detail: `Package '${params.package_name}' matches popular target '${squat.target}' via '${squat.primitive}' mutation.`,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (params.version_published_at_iso) {
|
|
254
|
+
const pubMs = Date.parse(params.version_published_at_iso);
|
|
255
|
+
if (Number.isFinite(pubMs)) {
|
|
256
|
+
const ageHours = (now - pubMs) / (3600 * 1000);
|
|
257
|
+
if (ageHours >= 0 && ageHours < params.policy.cooldown_hours) {
|
|
258
|
+
obs.push({
|
|
259
|
+
code: "RELEASE_COOLDOWN_QUARANTINE",
|
|
260
|
+
severity: "MEDIUM",
|
|
261
|
+
path: "<registry-metadata>",
|
|
262
|
+
attack_id: "T1195.002",
|
|
263
|
+
detail: `Release age is ${ageHours.toFixed(1)}h, below enterprise cooldown policy (${params.policy.cooldown_hours}h).`,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (
|
|
270
|
+
params.created_at_iso &&
|
|
271
|
+
params.weekly_downloads !== undefined &&
|
|
272
|
+
now - Date.parse(params.created_at_iso) < 30 * 24 * 3600 * 1000 &&
|
|
273
|
+
params.weekly_downloads < 100 &&
|
|
274
|
+
params.has_lifecycle_scripts
|
|
275
|
+
) {
|
|
276
|
+
obs.push({
|
|
277
|
+
code: "SLOPSQUAT_YOUNG_WITH_HOOKS",
|
|
278
|
+
severity: "HIGH",
|
|
279
|
+
path: "<registry-metadata>",
|
|
280
|
+
attack_id: "T1608.001",
|
|
281
|
+
detail: `Brand-new low-adoption package (<30d old, ${params.weekly_downloads} weekly downloads) defines install lifecycle scripts.`,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return obs;
|
|
286
|
+
}
|