coldpin 0.0.0-stage → 1.5.1

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.
Files changed (102) hide show
  1. package/ACCESSIBILITY.md +17 -0
  2. package/CHANGELOG.md +97 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/LICENSE +98 -0
  5. package/MAINTENANCE.md +33 -0
  6. package/README.md +142 -2
  7. package/SECURITY.md +34 -0
  8. package/TESTING.md +26 -0
  9. package/agents/coldpin-auditor.md +47 -0
  10. package/agents/coldpin-compliance.md +38 -0
  11. package/agents/coldpin-confusion-auditor.md +38 -0
  12. package/agents/coldpin-discoverer.md +37 -0
  13. package/agents/coldpin-forensics.md +38 -0
  14. package/agents/coldpin-inspector.md +37 -0
  15. package/agents/coldpin-manifest-auditor.md +38 -0
  16. package/assets/icon.svg +7 -0
  17. package/catalog/mcp-schema-pin.json +14 -0
  18. package/catalog/plugin.oms.sig +19 -0
  19. package/catalog/sigma/npx-suspicious-child-process-linux.yml +54 -0
  20. package/catalog/sigma/npx-suspicious-child-process.yml +49 -0
  21. package/catalog/triage-rules.json +104 -0
  22. package/docs/assets/readme-header.svg +21 -0
  23. package/docs/designs/SITEMAP.md +14 -0
  24. package/docs/designs/coldpin.md +68 -0
  25. package/docs/fact-ledger.md +36 -0
  26. package/docs/faq.md +31 -0
  27. package/docs/getting_started.md +62 -0
  28. package/docs/harnesses.md +45 -0
  29. package/docs/privacy.md +27 -0
  30. package/docs/verification/skill-inspector-self-audit.md +33 -0
  31. package/examples/.coldpin.policy.example.json +27 -0
  32. package/examples/.npmrc.example +8 -0
  33. package/examples/mcp_config.private-registry.example.json +42 -0
  34. package/hooks.json +47 -0
  35. package/lib/analysis/parity-and-bisect.mjs +1371 -0
  36. package/lib/analysis/static-triage.mjs +4572 -0
  37. package/lib/cache/sqlite-store.mjs +251 -0
  38. package/lib/cli.mjs +427 -0
  39. package/lib/compliance/audit-log.mjs +357 -0
  40. package/lib/config/policy.mjs +780 -0
  41. package/lib/core/path-confinement.mjs +289 -0
  42. package/lib/core/workflows.mjs +1205 -0
  43. package/lib/discovery/slopsquat-guard.mjs +289 -0
  44. package/lib/hook.mjs +1038 -0
  45. package/lib/intel/registry-osv.mjs +1681 -0
  46. package/lib/mcp/report-store.mjs +175 -0
  47. package/lib/mcp/server.mjs +1387 -0
  48. package/lib/mcp/stdio-transport.mjs +289 -0
  49. package/lib/mcp/tool-catalog.mjs +273 -0
  50. package/lib/mcp/types.mjs +95 -0
  51. package/lib/mcp.mjs +19 -0
  52. package/lib/quarantine/safe-unpack.mjs +568 -0
  53. package/lib/types.mjs +383 -0
  54. package/lib/verdict/engine-and-formatters.mjs +895 -0
  55. package/mcp_config.json +21 -0
  56. package/package.json +71 -3
  57. package/plugin.json +54 -0
  58. package/rules/AGENTS.md +18 -0
  59. package/rules/coldpin-incident-checklist.md +18 -0
  60. package/rules/coldpin-manifest-guard.md +14 -0
  61. package/server.json +38 -0
  62. package/skills/coldpin/BENCHMARK.md +166 -0
  63. package/skills/coldpin/SKILL.md +110 -0
  64. package/skills/coldpin/TEST.md +13 -0
  65. package/skills/coldpin/agents/openai.yaml +6 -0
  66. package/skills/coldpin/assets/icon.svg +7 -0
  67. package/skills/coldpin/assets/runtime-contract.yaml +105 -0
  68. package/skills/coldpin/evals/evals.json +60 -0
  69. package/skills/coldpin/references/aspect-compliance-audit.md +27 -0
  70. package/skills/coldpin/references/aspect-discovery.md +26 -0
  71. package/skills/coldpin/references/aspect-forensics-rea.md +26 -0
  72. package/skills/coldpin/references/aspect-inspection.md +26 -0
  73. package/skills/coldpin/references/aspect-manifest-confusion.md +26 -0
  74. package/skills/coldpin/references/enterprise-policy-schema.md +65 -0
  75. package/skills/coldpin/references/evidence-card-spec.md +27 -0
  76. package/skills/coldpin/references/rea-integration-playbook.md +34 -0
  77. package/skills/coldpin/references/threat-taxonomy.md +35 -0
  78. package/skills/coldpin/skill-card.md +62 -0
  79. package/skills/coldpin/skill.oms.sig +19 -0
  80. package/skills/coldpin/test_scenarios.yaml +61 -0
  81. package/skills/coldpin-audit/SKILL.md +39 -0
  82. package/skills/coldpin-incident/SKILL.md +37 -0
  83. package/src/analysis/parity-and-bisect.ts +1368 -0
  84. package/src/analysis/static-triage.ts +4569 -0
  85. package/src/cache/sqlite-store.ts +248 -0
  86. package/src/cli.ts +424 -0
  87. package/src/compliance/audit-log.ts +354 -0
  88. package/src/config/policy.ts +777 -0
  89. package/src/core/path-confinement.ts +286 -0
  90. package/src/core/workflows.ts +1202 -0
  91. package/src/discovery/slopsquat-guard.ts +286 -0
  92. package/src/hook.ts +1035 -0
  93. package/src/intel/registry-osv.ts +1678 -0
  94. package/src/mcp/report-store.ts +172 -0
  95. package/src/mcp/server.ts +1384 -0
  96. package/src/mcp/stdio-transport.ts +286 -0
  97. package/src/mcp/tool-catalog.ts +270 -0
  98. package/src/mcp/types.ts +92 -0
  99. package/src/mcp.ts +16 -0
  100. package/src/quarantine/safe-unpack.ts +565 -0
  101. package/src/types.ts +380 -0
  102. package/src/verdict/engine-and-formatters.ts +892 -0
@@ -0,0 +1,289 @@
1
+ import { levenshtein } from "../config/policy.mjs";
2
+
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 = [
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 = {
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 ) {
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 ) {
128
+ return name.toLowerCase().replace(/[-_.]/g, "");
129
+ }
130
+
131
+ function sortedTokens(name ) {
132
+ return name
133
+ .toLowerCase()
134
+ .split(/[-_.]/)
135
+ .filter(Boolean)
136
+ .sort()
137
+ .join("-");
138
+ }
139
+
140
+ function stripCommonSuffix(name ) {
141
+ return name.toLowerCase().replace(/-(js|ts|cli|node|npm|pkg|official|lib)$/, "");
142
+ }
143
+
144
+ function isSingleTransposition(a , b ) {
145
+ if (a.length !== b.length || a.length < 3) return false;
146
+ const diffs = [];
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
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
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 ,
174
+ corpus = TOP_NPM_TARGETS,
175
+ ) {
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
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+ ) {
234
+ const obs = [];
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
+ }
287
+
288
+
289
+ //# sourceURL=discovery/slopsquat-guard.ts