weavatrix 0.3.13 → 1.0.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.
Files changed (303) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +231 -199
  3. package/bin/native/darwin-arm64/weavatrix +0 -0
  4. package/bin/native/darwin-x64/weavatrix +0 -0
  5. package/bin/native/linux-arm64/weavatrix +0 -0
  6. package/bin/native/linux-x64/weavatrix +0 -0
  7. package/bin/native/win32-arm64/weavatrix.exe +0 -0
  8. package/bin/native/win32-x64/weavatrix.exe +0 -0
  9. package/bin/resolve-binary.mjs +73 -0
  10. package/bin/run-native.mjs +26 -0
  11. package/bin/weavatrix-mcp.mjs +7 -6
  12. package/bin/weavatrix.mjs +5 -0
  13. package/package.json +8 -65
  14. package/skill/SKILL.md +62 -374
  15. package/skill/agents/openai.yaml +4 -0
  16. package/skill/references/tool-routing.md +45 -0
  17. package/SECURITY.md +0 -101
  18. package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
  19. package/docs/agent-task-benchmark.md +0 -58
  20. package/docs/releases/v0.2.19.md +0 -33
  21. package/docs/releases/v0.3.0.md +0 -43
  22. package/docs/releases/v0.3.1.md +0 -30
  23. package/docs/releases/v0.3.10.md +0 -76
  24. package/docs/releases/v0.3.11.md +0 -55
  25. package/docs/releases/v0.3.12.md +0 -44
  26. package/docs/releases/v0.3.13.md +0 -34
  27. package/docs/releases/v0.3.2.md +0 -15
  28. package/docs/releases/v0.3.3.md +0 -25
  29. package/docs/releases/v0.3.4.md +0 -40
  30. package/docs/releases/v0.3.5.md +0 -50
  31. package/docs/releases/v0.3.6.md +0 -44
  32. package/docs/releases/v0.3.7.md +0 -37
  33. package/docs/releases/v0.3.8.md +0 -21
  34. package/docs/releases/v0.3.9.md +0 -36
  35. package/scripts/run-agent-task-benchmark.mjs +0 -118
  36. package/src/analysis/allowed-test-runner.js +0 -70
  37. package/src/analysis/architecture/contract-graph.js +0 -119
  38. package/src/analysis/architecture/contract-schema.js +0 -110
  39. package/src/analysis/architecture/contract-storage.js +0 -35
  40. package/src/analysis/architecture/contract-verification.js +0 -168
  41. package/src/analysis/architecture-contract.js +0 -16
  42. package/src/analysis/audit-debt.js +0 -94
  43. package/src/analysis/audit-extensions.js +0 -60
  44. package/src/analysis/cargo-dependency-evidence.js +0 -108
  45. package/src/analysis/cargo-manifests.js +0 -81
  46. package/src/analysis/change-classification/diff-parser.js +0 -103
  47. package/src/analysis/change-classification/options.js +0 -40
  48. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  49. package/src/analysis/change-classification.js +0 -188
  50. package/src/analysis/coverage-reports.js +0 -235
  51. package/src/analysis/cycle-route.js +0 -14
  52. package/src/analysis/data-flow-evidence.js +0 -114
  53. package/src/analysis/dead-check.js +0 -300
  54. package/src/analysis/dead-code-review/candidates.js +0 -194
  55. package/src/analysis/dead-code-review/policy.js +0 -23
  56. package/src/analysis/dead-code-review.js +0 -119
  57. package/src/analysis/dep-check-ecosystems.js +0 -205
  58. package/src/analysis/dep-check.js +0 -290
  59. package/src/analysis/dep-rules.js +0 -10
  60. package/src/analysis/dependency/conventions.js +0 -16
  61. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  62. package/src/analysis/dependency/source-references.js +0 -21
  63. package/src/analysis/duplicate-groups.js +0 -104
  64. package/src/analysis/duplicates-worker.js +0 -11
  65. package/src/analysis/duplicates.compute.js +0 -269
  66. package/src/analysis/duplicates.js +0 -15
  67. package/src/analysis/duplicates.run.js +0 -52
  68. package/src/analysis/duplicates.tokenize.js +0 -199
  69. package/src/analysis/endpoints/common.js +0 -62
  70. package/src/analysis/endpoints/extract.js +0 -107
  71. package/src/analysis/endpoints/inventory.js +0 -84
  72. package/src/analysis/endpoints/mounts.js +0 -129
  73. package/src/analysis/endpoints-java.js +0 -260
  74. package/src/analysis/endpoints-rust.js +0 -124
  75. package/src/analysis/endpoints.js +0 -3
  76. package/src/analysis/findings.js +0 -70
  77. package/src/analysis/git-history/analytics.js +0 -177
  78. package/src/analysis/git-history/collector.js +0 -67
  79. package/src/analysis/git-history/options.js +0 -66
  80. package/src/analysis/git-history.js +0 -143
  81. package/src/analysis/git-ref-graph.js +0 -76
  82. package/src/analysis/go-dependency-evidence.js +0 -62
  83. package/src/analysis/graph-analysis.aggregate.js +0 -295
  84. package/src/analysis/graph-analysis.edges.js +0 -24
  85. package/src/analysis/graph-analysis.js +0 -7
  86. package/src/analysis/graph-analysis.refs.js +0 -154
  87. package/src/analysis/graph-analysis.summaries.js +0 -65
  88. package/src/analysis/health-capabilities.js +0 -83
  89. package/src/analysis/hot-path-review.js +0 -266
  90. package/src/analysis/http-contract-wrappers.js +0 -241
  91. package/src/analysis/http-contracts/analysis.js +0 -179
  92. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  93. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  94. package/src/analysis/http-contracts/graph-context.js +0 -143
  95. package/src/analysis/http-contracts/matching.js +0 -61
  96. package/src/analysis/http-contracts/shared.js +0 -85
  97. package/src/analysis/http-contracts.js +0 -6
  98. package/src/analysis/internal-audit/dependency-health.js +0 -113
  99. package/src/analysis/internal-audit/python-manifests.js +0 -78
  100. package/src/analysis/internal-audit/repo-files.js +0 -50
  101. package/src/analysis/internal-audit/supply-chain.js +0 -149
  102. package/src/analysis/internal-audit.collect.js +0 -213
  103. package/src/analysis/internal-audit.js +0 -9
  104. package/src/analysis/internal-audit.reach.js +0 -173
  105. package/src/analysis/internal-audit.run.js +0 -256
  106. package/src/analysis/java-source.js +0 -36
  107. package/src/analysis/jvm-artifact-index.js +0 -87
  108. package/src/analysis/jvm-dependency-evidence.js +0 -138
  109. package/src/analysis/jvm-manifests.js +0 -114
  110. package/src/analysis/manifests.js +0 -123
  111. package/src/analysis/package-reachability.js +0 -39
  112. package/src/analysis/source-complexity.ast.js +0 -97
  113. package/src/analysis/source-complexity.constants.js +0 -55
  114. package/src/analysis/source-complexity.js +0 -14
  115. package/src/analysis/source-complexity.report.js +0 -81
  116. package/src/analysis/source-complexity.walk.js +0 -228
  117. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  118. package/src/analysis/source-correctness.js +0 -222
  119. package/src/analysis/static-test-reachability.js +0 -150
  120. package/src/analysis/structure/dependency-graph.js +0 -151
  121. package/src/analysis/structure/findings.js +0 -162
  122. package/src/analysis/task-retrieval.js +0 -107
  123. package/src/analysis/transport-contracts.js +0 -224
  124. package/src/analysis/transport-runtime-evidence.js +0 -155
  125. package/src/analysis-kit.mjs +0 -17
  126. package/src/bounds.js +0 -4
  127. package/src/build-graph.js +0 -209
  128. package/src/child-env.js +0 -7
  129. package/src/config.js +0 -5
  130. package/src/extension/local-services.mjs +0 -75
  131. package/src/git-exec.js +0 -67
  132. package/src/graph/build-worker.js +0 -49
  133. package/src/graph/builder/go-receiver-resolution.js +0 -112
  134. package/src/graph/builder/js/dynamic-import.js +0 -26
  135. package/src/graph/builder/js/queries.js +0 -48
  136. package/src/graph/builder/lang-csharp.js +0 -40
  137. package/src/graph/builder/lang-css.js +0 -29
  138. package/src/graph/builder/lang-go.js +0 -140
  139. package/src/graph/builder/lang-html.js +0 -29
  140. package/src/graph/builder/lang-java-calls.js +0 -142
  141. package/src/graph/builder/lang-java.js +0 -215
  142. package/src/graph/builder/lang-js.js +0 -291
  143. package/src/graph/builder/lang-python.js +0 -235
  144. package/src/graph/builder/lang-rust-calls.js +0 -63
  145. package/src/graph/builder/lang-rust.js +0 -299
  146. package/src/graph/builder/lang-solidity.js +0 -126
  147. package/src/graph/builder/lang-sql.js +0 -263
  148. package/src/graph/builder/pass2-resolution.js +0 -81
  149. package/src/graph/builder/spec-pkg.js +0 -87
  150. package/src/graph/community.js +0 -27
  151. package/src/graph/edge-provenance.js +0 -31
  152. package/src/graph/file-lock.js +0 -69
  153. package/src/graph/freshness-probe.js +0 -142
  154. package/src/graph/graph-filter.js +0 -63
  155. package/src/graph/incremental-refresh.js +0 -235
  156. package/src/graph/internal-builder.barrels.js +0 -235
  157. package/src/graph/internal-builder.build.js +0 -300
  158. package/src/graph/internal-builder.java.js +0 -33
  159. package/src/graph/internal-builder.js +0 -12
  160. package/src/graph/internal-builder.langs.js +0 -157
  161. package/src/graph/internal-builder.pass2.js +0 -163
  162. package/src/graph/internal-builder.resolvers.js +0 -286
  163. package/src/graph/layout.js +0 -51
  164. package/src/graph/node-id.js +0 -7
  165. package/src/graph/parser-artifact-boundary.js +0 -55
  166. package/src/graph/relations.js +0 -4
  167. package/src/graph/repo-registry.js +0 -124
  168. package/src/graph/resolvers/rust.js +0 -117
  169. package/src/infra/infra-items.js +0 -255
  170. package/src/infra/infra-registry.js +0 -184
  171. package/src/infra/infra.detect.js +0 -119
  172. package/src/infra/infra.js +0 -38
  173. package/src/infra/infra.match.js +0 -102
  174. package/src/infra/infra.scan.js +0 -93
  175. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  176. package/src/mcp/architecture-bootstrap.mjs +0 -168
  177. package/src/mcp/architecture-starter.mjs +0 -234
  178. package/src/mcp/catalog.mjs +0 -233
  179. package/src/mcp/company-contract-page.mjs +0 -142
  180. package/src/mcp/company-contract-reconcile.mjs +0 -87
  181. package/src/mcp/company-contract-verdict.mjs +0 -42
  182. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  183. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  184. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  185. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  186. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  187. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  188. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  189. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  190. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  191. package/src/mcp/evidence-snapshot.mjs +0 -50
  192. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  193. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  194. package/src/mcp/extension-api.mjs +0 -77
  195. package/src/mcp/git-output.mjs +0 -7
  196. package/src/mcp/graph/context-core.mjs +0 -111
  197. package/src/mcp/graph/context-seeds.mjs +0 -207
  198. package/src/mcp/graph/context-state.mjs +0 -85
  199. package/src/mcp/graph/reverse-reach.mjs +0 -42
  200. package/src/mcp/graph/tools-core.mjs +0 -143
  201. package/src/mcp/graph/tools-query.mjs +0 -276
  202. package/src/mcp/graph-context.mjs +0 -5
  203. package/src/mcp/graph-diff.mjs +0 -218
  204. package/src/mcp/health/audit-format.mjs +0 -199
  205. package/src/mcp/health/audit.mjs +0 -174
  206. package/src/mcp/health/dead-code.mjs +0 -110
  207. package/src/mcp/health/duplicates.mjs +0 -85
  208. package/src/mcp/health/endpoints.mjs +0 -71
  209. package/src/mcp/health/structure.mjs +0 -219
  210. package/src/mcp/runtime-version.mjs +0 -31
  211. package/src/mcp/server/auto-refresh.mjs +0 -66
  212. package/src/mcp/server/runtime-config.mjs +0 -43
  213. package/src/mcp/server/shutdown.mjs +0 -40
  214. package/src/mcp/staleness-notice.mjs +0 -20
  215. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  216. package/src/mcp/sync/evidence-common.mjs +0 -88
  217. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  218. package/src/mcp/sync/evidence-health.mjs +0 -56
  219. package/src/mcp/sync/evidence-packages.mjs +0 -95
  220. package/src/mcp/sync/payload-common.mjs +0 -97
  221. package/src/mcp/sync/payload-v2.mjs +0 -54
  222. package/src/mcp/sync/payload-v3.mjs +0 -79
  223. package/src/mcp/sync-evidence.mjs +0 -23
  224. package/src/mcp/sync-payload.mjs +0 -70
  225. package/src/mcp/tool-result.mjs +0 -54
  226. package/src/mcp/tools-actions.mjs +0 -11
  227. package/src/mcp/tools-architecture.mjs +0 -177
  228. package/src/mcp/tools-company.mjs +0 -251
  229. package/src/mcp/tools-context.mjs +0 -222
  230. package/src/mcp/tools-endpoints.mjs +0 -207
  231. package/src/mcp/tools-graph-hubs.mjs +0 -78
  232. package/src/mcp/tools-graph.mjs +0 -17
  233. package/src/mcp/tools-health.mjs +0 -24
  234. package/src/mcp/tools-history.mjs +0 -28
  235. package/src/mcp/tools-impact-change.mjs +0 -220
  236. package/src/mcp/tools-impact-precision.mjs +0 -89
  237. package/src/mcp/tools-impact.mjs +0 -169
  238. package/src/mcp/tools-source.mjs +0 -238
  239. package/src/mcp/tools-verified-change.mjs +0 -200
  240. package/src/mcp-rg.mjs +0 -50
  241. package/src/mcp-runtime.mjs +0 -2
  242. package/src/mcp-server.mjs +0 -298
  243. package/src/mcp-source-tools.mjs +0 -163
  244. package/src/path-classification.js +0 -220
  245. package/src/path-ignore.js +0 -69
  246. package/src/precision/lsp-client/constants.js +0 -12
  247. package/src/precision/lsp-client/environment.js +0 -20
  248. package/src/precision/lsp-client/errors.js +0 -15
  249. package/src/precision/lsp-client/lifecycle.js +0 -114
  250. package/src/precision/lsp-client/message-parser.js +0 -81
  251. package/src/precision/lsp-client/protocol.js +0 -212
  252. package/src/precision/lsp-client/registry.js +0 -59
  253. package/src/precision/lsp-client/repo-uri.js +0 -60
  254. package/src/precision/lsp-client/stdio-client.js +0 -140
  255. package/src/precision/lsp-client.js +0 -10
  256. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  257. package/src/precision/lsp-overlay/build.js +0 -261
  258. package/src/precision/lsp-overlay/contract.js +0 -61
  259. package/src/precision/lsp-overlay/reference-results.js +0 -108
  260. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  261. package/src/precision/lsp-overlay/source-session.js +0 -142
  262. package/src/precision/lsp-overlay/store.js +0 -150
  263. package/src/precision/lsp-overlay/target-index.js +0 -152
  264. package/src/precision/lsp-overlay/target-query.js +0 -55
  265. package/src/precision/lsp-overlay.js +0 -11
  266. package/src/precision/symbol-query.js +0 -224
  267. package/src/precision/typescript-lsp-provider.js +0 -12
  268. package/src/precision/typescript-provider/client.js +0 -89
  269. package/src/precision/typescript-provider/discovery.js +0 -124
  270. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  271. package/src/precision/typescript-provider/project-host.js +0 -254
  272. package/src/precision/typescript-provider/project-safety.js +0 -166
  273. package/src/precision/typescript-provider/reference-usage.js +0 -53
  274. package/src/process.js +0 -95
  275. package/src/repo-path.js +0 -53
  276. package/src/scan/discover.inventory.js +0 -78
  277. package/src/scan/discover.js +0 -5
  278. package/src/scan/discover.list.js +0 -79
  279. package/src/scan/discover.stack.js +0 -227
  280. package/src/scan/search.core.js +0 -24
  281. package/src/scan/search.git.js +0 -102
  282. package/src/scan/search.js +0 -9
  283. package/src/scan/search.node.js +0 -83
  284. package/src/scan/search.preview.js +0 -49
  285. package/src/scan/search.rg.js +0 -145
  286. package/src/security/advisory-store.js +0 -172
  287. package/src/security/installed-jvm-rust.js +0 -46
  288. package/src/security/installed.js +0 -280
  289. package/src/security/malware-file-heuristics.js +0 -121
  290. package/src/security/malware-heuristics.exclusions.js +0 -134
  291. package/src/security/malware-heuristics.js +0 -15
  292. package/src/security/malware-heuristics.roots.js +0 -145
  293. package/src/security/malware-heuristics.scan.js +0 -89
  294. package/src/security/malware-heuristics.sweep.js +0 -122
  295. package/src/security/malware-scoring.js +0 -105
  296. package/src/security/match.js +0 -85
  297. package/src/security/registry-sig.classify.js +0 -137
  298. package/src/security/registry-sig.js +0 -18
  299. package/src/security/registry-sig.rules.js +0 -192
  300. package/src/security/rust-advisory-report.js +0 -60
  301. package/src/security/typosquat.js +0 -81
  302. package/src/util.js +0 -40
  303. package/src/version.js +0 -7
@@ -1,137 +0,0 @@
1
- // Pure classifiers for registry-sig.js: install-script/content/.pth/resolved-URL classification and
2
- // the doc/benign-URL noise filters.
3
-
4
- import { CONTENT_RULES } from "./registry-sig.rules.js";
5
-
6
- // ---- install-script classification (package.json preinstall/install/postinstall) ----
7
- const FETCH_RE = /\b(curl|wget|iwr|invoke-webrequest|certutil\s+-urlcache)\b|https?:\/\//i;
8
- const EXEC_RE = /\|\s*(sh|bash|node|cmd|powershell|pwsh)\b|\b(node|python[0-9]?|perl|ruby|deno)\s+-e\s|python[0-9]?\s+-c\s|base64\s+(-d|--decode)|\beval\b|frombase64string|-enc(odedcommand)?\b|\biex\b|invoke-expression/i;
9
- // routine native-build steps — never signals on their own
10
- const BENIGN_ARG = "[\\w./:@=+,-]+";
11
- const BENIGN_RE = new RegExp(`^(node-gyp\\s+rebuild|node-pre-gyp\\s+install(\\s+${BENIGN_ARG})*|prebuild-install(\\s+${BENIGN_ARG})*|node\\s+(scripts?|install|postinstall|lib)\\/[\\w./-]+\\.js(\\s+${BENIGN_ARG})*|electron-rebuild(\\s+${BENIGN_ARG})*|patch-package|husky(\\s+install)?|opencollective(\\s+${BENIGN_ARG})*|is-ci(\\s+${BENIGN_ARG})*)$`, "i");
12
- const SHELL_CHAIN_RE = /&&|\|\||[;|`]|[$]\(|\r|\n/i;
13
- function isBenignLifecycleScript(script) {
14
- return !SHELL_CHAIN_RE.test(script) && BENIGN_RE.test(script);
15
- }
16
-
17
- // → [{key, severity, nearZeroFp, what, snippet}] for one package's scripts object
18
- export function classifyInstallScript(scripts = {}) {
19
- const signals = [];
20
- for (const hook of ["preinstall", "install", "postinstall", "prepare"]) {
21
- const s = String(scripts[hook] || "").trim();
22
- if (!s || isBenignLifecycleScript(s)) continue;
23
- const fetches = FETCH_RE.test(s);
24
- const execs = EXEC_RE.test(s);
25
- if (fetches && execs) {
26
- signals.push({ key: "install-script-beacon", severity: "critical", nearZeroFp: true, what: `${hook} downloads AND executes (fetch+exec)`, snippet: s.slice(0, 200) });
27
- } else if (fetches) {
28
- signals.push({ key: "install-script-fetch", severity: "high", nearZeroFp: false, what: `${hook} reaches the network`, snippet: s.slice(0, 200) });
29
- } else if (execs) {
30
- signals.push({ key: "install-script-exec", severity: "medium", nearZeroFp: false, noisy: true, what: `${hook} uses eval/inline-node/base64`, snippet: s.slice(0, 200) });
31
- }
32
- }
33
- return signals;
34
- }
35
-
36
- // → signals[] for a chunk of file text (fallback scanning + rg-hit validation)
37
- export function classifyContent(text) {
38
- const t = String(text || "");
39
- let out = [];
40
- for (const r of CONTENT_RULES) if (r.re.test(t)) out.push(r);
41
- const strongerUrl = out.some((r) => ["exfil-url", "exfil-ip", "cloud-metadata-url", "network-url"].includes(r.key));
42
- const docOnlyUrl = /\b(see|readme|docs?|documentation)\b[\s\S]{0,80}https?:\/\//i.test(t) || /https?:\/\/[^'"`\s)\\]+\/docs\b/i.test(t);
43
- if (strongerUrl || docOnlyUrl) out = out.filter((r) => r.key !== "hardcoded-url");
44
- return out;
45
- }
46
-
47
- const PTH_SUSPICIOUS_IMPORT_RE = /^\s*import\s+.*\b(exec|eval|compile|__import__|os\.system|subprocess|socket|requests|urllib|httpx|base64|b64decode|marshal|zlib|ctypes)\b/i;
48
- export function classifyPythonPth(text) {
49
- const signals = [];
50
- const lines = String(text || "").split(/\r?\n/);
51
- lines.forEach((line, i) => {
52
- if (!PTH_SUSPICIOUS_IMPORT_RE.test(line)) return;
53
- signals.push({
54
- key: "python-pth-startup-exec",
55
- severity: "high",
56
- nearZeroFp: false,
57
- what: "Python .pth startup import with executable/network/decoder behavior",
58
- snippet: line.trim().slice(0, 200),
59
- line: i + 1,
60
- });
61
- });
62
- return signals;
63
- }
64
-
65
- // ---- noise filters for the WEAK URL rules only (hardcoded-url, network-url). LICENSE files,
66
- // comments and doc-links are where ~100% of their false positives live; the strong rules
67
- // (miner/shell/exfil-url) still scan those files — a payload hidden in LICENSE stays caught. ----
68
- export const NOISY_URL_KEYS = new Set(["hardcoded-url", "network-url"]);
69
-
70
- const DOC_BASENAME_RE = /^((license|licence|notice|copying|copyright|authors|contributors|changelog|changes|history|readme|third[-_]?party[-_]?notices?|code[-_]?of[-_]?conduct)(\.(md|markdown|mdown|mkd|txt|rst|adoc|html?))?|licen[cs]es?[-_][\w.-]+|patents)$/i;
71
- const DOC_EXT_RE = /\.(markdown|mdown|mkd|txt|rst|adoc|asciidoc|pod)$/i;
72
-
73
- // prose/license file → URL evidence there is documentation, not behavior
74
- export function isDocFile(file) {
75
- const base = String(file || "").replace(/\\/g, "/").split("/").pop() || "";
76
- return DOC_BASENAME_RE.test(base) || DOC_EXT_RE.test(base);
77
- }
78
-
79
- // comment openers BEFORE a URL ("// see", "* {@link", "# docs"); `//` not preceded by ':'/quote so
80
- // protocol tails and '//'-in-string don't count; '#' not a hex color / shebang
81
- const COMMENT_MARKER_RE = /(^|[^:'"`/])\/\/|\/\*|<!--|^\s*\*\s|\n\s*\*\s|(^|[\s({;,=])#(?!!|[0-9a-f]{3,8}\b)/i;
82
- const DOC_WORD_PRE_RE = /\b(see|docs?|documentation|learn more|read more|more info(rmation)?|for details|refer(ence)? to|guide|manual|tutorial|homepage|website|link|visit|licen[cs]ed?|copyright|spec(ification)?|polyfill|based on|inspired by|ported from|wiki|report(ed)?\s+(at|to|bugs?|issues?)|file (an? )?(issue|bug)|available at|found at|thanks to)\b|@(see|link|license)\b|["']?\$schema["']?\s*:|\]\(\s*$/i;
83
- const DOC_WORD_POST_RE = /^[):,'"`\]\s]{0,6}\b(spec(ification)?|docs?|documentation|standard|for (more|details)|page)\b/i;
84
- // hosts that only serve standards/licenses/docs/registry pages — not attacker-controllable payload hosts
85
- const BENIGN_URL_HOSTS = [
86
- "w3.org", "ietf.org", "rfc-editor.org", "iana.org", "whatwg.org", "ecma-international.org", "tc39.es",
87
- "unicode.org", "schema.org", "json-schema.org", "schemastore.org", "spdx.org", "semver.org",
88
- "apache.org", "opensource.org", "gnu.org", "creativecommons.org", "choosealicense.com",
89
- "mozilla.org", "nodejs.org", "npmjs.com", "npmjs.org", "yarnpkg.com", "python.org", "pypi.org",
90
- "golang.org", "go.dev", "godoc.org", "readthedocs.io", "readthedocs.org", "editorconfig.org",
91
- "aka.ms", "example.com", "example.org", "example.net",
92
- ];
93
- const DOC_URL_PATH_RE = /\/(docs?|documentation|wiki|issues?|pull|blob|tree|releases|licenses?|rfc\d*|help|manual|guide|spec|schemas?)([/#?.]|$)/i;
94
- const URL_TOKEN_RE = /https?:\/\/[^\s'"`)\\<>]+/gi;
95
-
96
- function isBenignUrl(url) {
97
- try {
98
- const u = new URL(url);
99
- const host = u.host.replace(/^www\./, "").replace(/:\d+$/, "").toLowerCase();
100
- if (BENIGN_URL_HOSTS.some((h) => host === h || host.endsWith(`.${h}`))) return true;
101
- return DOC_URL_PATH_RE.test(u.pathname);
102
- } catch { return false; }
103
- }
104
-
105
- // snippet-level classifier: true when EVERY URL in the snippet sits in doc/comment context — a
106
- // comment opener before the first URL comments out the rest of the line; otherwise each URL needs
107
- // its own doc-word neighborhood or a benign standards/docs host. Conservative on purpose: one
108
- // non-benign URL keeps the whole snippet as evidence.
109
- export function isBenignUrlContext(text) {
110
- const s = String(text || "");
111
- const urls = [...s.matchAll(URL_TOKEN_RE)];
112
- if (!urls.length) return false;
113
- if (COMMENT_MARKER_RE.test(s.slice(0, urls[0].index))) return true;
114
- return urls.every((m) => {
115
- const pre = s.slice(Math.max(0, m.index - 80), m.index);
116
- const post = s.slice(m.index + m[0].length, m.index + m[0].length + 48);
117
- return DOC_WORD_PRE_RE.test(pre) || DOC_WORD_POST_RE.test(post) || isBenignUrl(m[0]);
118
- });
119
- }
120
-
121
- // packages whose JOB is talking to cloud endpoints (IMDS auth, vault, STS) — mutes cloud-metadata-url
122
- // and the weak hardcoded-url for them ONLY. hardcoded-url never escalates (weak) and is hidden whenever
123
- // a stronger URL rule fires, so nothing real is lost; a trojaned version still trips every other rule.
124
- const CLOUD_SDK_PKG_RE = /^(aws-sdk|gcp-metadata|google-auth-library|azure-identity|boto3|botocore|google-auth|msrestazure|cloud\.google\.com\/go(\/.*)?|github\.com\/aws\/aws-sdk-go(-v2)?(\/.*)?|github\.com\/[aA]zure\/azure-sdk-for-go(\/.*)?)$|^@(aws-sdk|azure|google-cloud)\//;
125
- const CLOUD_SDK_MUTED_KEYS = new Set(["cloud-metadata-url"]);
126
- export function isCloudSdkMetadataUse(pkg, ruleKey) {
127
- return CLOUD_SDK_MUTED_KEYS.has(ruleKey) && CLOUD_SDK_PKG_RE.test(String(pkg || ""));
128
- }
129
-
130
- // package-lock `resolved` origin check: anything outside the big registries is worth a look.
131
- const REGISTRY_RE = /^https:\/\/(registry\.npmjs\.org|registry\.yarnpkg\.com|registry\.npmmirror\.com)\//i;
132
- export function classifyResolvedUrl(resolved) {
133
- const r = String(resolved || "");
134
- if (!r || REGISTRY_RE.test(r) || r.startsWith("file:")) return null; // file: = workspace/link, common
135
- if (/^git\+|^git:|github\.com\//i.test(r)) return { key: "non-registry-source", severity: "medium", nearZeroFp: false, what: "installed from git, not the npm registry (no registry audit trail)", snippet: r.slice(0, 200) };
136
- return { key: "non-registry-source", severity: "medium", nearZeroFp: false, what: "installed from a non-registry URL", snippet: r.slice(0, 200) };
137
- }
@@ -1,18 +0,0 @@
1
- // Curated malware-heuristic signature table (defensive scanning of INSTALLED dependencies) + pure
2
- // classifiers. Same philosophy as infra-registry.js: deterministic patterns, near-zero-FP rules marked
3
- // explicitly, and an allowlist that downgrades ONLY the noisy rules — NEVER the smoking-gun ones
4
- // (miners, fetch+exec): supply-chain attacks trojan previously-good packages (event-stream lesson).
5
- // DEPS_SECURITY_PLAN P5.
6
- // Facade: signature tables live in registry-sig.rules.js, classifiers in registry-sig.classify.js.
7
-
8
- export { MALWARE_ALLOWLIST, CONTENT_RULES } from "./registry-sig.rules.js";
9
- export {
10
- classifyInstallScript,
11
- classifyContent,
12
- classifyPythonPth,
13
- NOISY_URL_KEYS,
14
- isDocFile,
15
- isBenignUrlContext,
16
- isCloudSdkMetadataUse,
17
- classifyResolvedUrl,
18
- } from "./registry-sig.classify.js";
@@ -1,192 +0,0 @@
1
- // Signature tables for registry-sig.js: the malware allowlist and the content-rule set.
2
-
3
- // Packages with famously "suspicious-looking but legit" behavior: native builds, postinstall banners,
4
- // heavily-minified bundles. Downgrades obfuscation-style signals only.
5
- export const MALWARE_ALLOWLIST = new Set([
6
- "esbuild", "sharp", "node-gyp", "husky", "playwright", "@playwright/test", "puppeteer", "electron",
7
- "better-sqlite3", "bcrypt", "fsevents", "core-js", "styled-components", "cypress", "sentry-cli",
8
- "@sentry/cli", "node-sass", "sqlite3", "grpc", "@grpc/grpc-js", "protobufjs", "swc", "@swc/core",
9
- "workerd", "sass-embedded", "canvas", "re2", "cpu-features", "ssh2", "argon2", "tree-sitter",
10
- ]);
11
-
12
- // One source of truth for beacon/exfil endpoints: exfil-url MATCHES them, the weaker URL rules
13
- // EXCLUDE them (lookahead) so a single URL never counts as two distinct escalation keys.
14
- // webhook.site / oast.* / canarytokens / dnslog.cn: Shai-Hulud-era exfil + OOB-callback services.
15
- const EXFIL_HOSTS = "discord(app)?\\.com/api/webhooks|hooks\\.slack\\.com/services|api\\.telegram\\.org/bot|pastebin\\.com/raw|burpcollaborator|oastify\\.com|oast\\.(pro|live|fun|me|site|online)|interact\\.sh|pipedream\\.net|requestbin|webhook\\.site|canarytokens\\.(com|org)|dnslog\\.cn";
16
- // external URL that is NOT an exfil endpoint (owned by exfil-url) and NOT a raw IP (owned by exfil-ip)
17
- const PLAIN_EXTERNAL_URL = `https?://(?!(${EXFIL_HOSTS})|[0-9]{1,3}\\.|localhost\\b|127\\.|0\\.0\\.0\\.0|10\\.|192\\.168\\.|169\\.254\\.|172\\.(1[6-9]|2\\d|3[01])\\.)[a-z0-9][^'"\`\\s)\\\\]+`;
18
-
19
- // ---- content rules (scanned over node_modules file text; `pattern` is ripgrep-safe ERE, `re` is the
20
- // JS validator used both to classify rg hits and by the no-rg fallback) ----
21
- export const CONTENT_RULES = [
22
- {
23
- key: "crypto-miner",
24
- severity: "critical",
25
- nearZeroFp: true,
26
- // mining-pool protocol + specific miner names / pool hosts / xmrig flags. Deliberately NO generic
27
- // words ("miner", "hash") — those false-positive on legit crypto/hashing libs.
28
- pattern: "stratum\\+(tcp|ssl)://|xmrig|cryptonight|randomx|coinhive|coinimp|cryptoloot|jsecoin|webminepool|minexmr|supportxmr|nanopool\\.org|nicehash\\.com|minergate|--donate-level|--coin\\s+monero",
29
- re: /stratum\+(tcp|ssl):\/\/|xmrig|cryptonight|randomx|coinhive|coinimp|cryptoloot|jsecoin|webminepool|minexmr|supportxmr|nanopool\.org|nicehash\.com|minergate|--donate-level|--coin\s+monero/i,
30
- what: "crypto-miner signature (mining pool protocol / miner name / xmrig flag)",
31
- },
32
- {
33
- key: "reverse-shell",
34
- severity: "critical",
35
- nearZeroFp: true,
36
- // canonical reverse/bind shells — a shell wired to a socket. Essentially never legitimate inside a
37
- // published package: /dev/tcp redirection, netcat -e, interactive-shell redirect, mkfifo pipe shell.
38
- // The rg pre-filter must stay a superset of `re` below: rg surfaces lines matching this string and
39
- // only then is `re` applied to confirm, so a narrower pre-filter silently drops real reverse shells
40
- // (e.g. socket + pty.spawn / os.dup2 / subprocess, or a default socket.socket() without SOCK_STREAM).
41
- pattern: "/dev/tcp/[0-9]|\\bnc(at)?\\s+-e\\b|\\b(ba)?sh\\s+-i\\b\\s*(2)?>&|mkfifo\\b.{0,60}(ba)?sh\\b|0<&196|socket\\.socket\\(.{0,120}(connect|SOCK_STREAM).{0,180}(/bin/sh|subprocess|pty\\.spawn|os\\.dup2)",
42
- re: /\/dev\/tcp\/[0-9]|\bnc(at)?\s+-e\b|\b(ba)?sh\s+-i\b\s*(2)?>&|mkfifo\b[\s\S]{0,60}?\b(ba)?sh\b|0<&196|socket\.socket\([\s\S]{0,120}?(connect|SOCK_STREAM)[\s\S]{0,180}?(\/bin\/sh|subprocess|pty\.spawn|os\.dup2)/i,
43
- what: "reverse/bind-shell pattern (interactive shell wired to a socket)",
44
- },
45
- {
46
- key: "sensitive-file-read",
47
- severity: "medium", // strong signal, but backup/dotfile tools touch these too → escalates via co-occurrence
48
- nearZeroFp: false,
49
- // rg pre-filter is the bare path; the JS re REQUIRES a read/copy/exfil verb on the same line — a
50
- // credential PATH alone (docs, READMEs, comments) is not a read (that was the app-builder-lib /
51
- // bun-types false positive). /etc/passwd + .netrc dropped (too common in prose).
52
- pattern: "\\.ssh/(id_rsa|id_ed25519|id_dsa|authorized_keys)|\\.aws/credentials|\\.git-credentials|/etc/shadow|\\.docker/config\\.json|\\.kube/config",
53
- re: /(readFileSync|readFile|createReadStream|openSync|\.read\(|copyFile|readlink|Get-Content|\bcat\s|\bscp\s|\bcurl\b[^\n]*-[TF])[\s\S]{0,80}?(\.ssh\/(id_(rsa|ed25519|dsa)|authorized_keys)|\.aws\/credentials|\.git-credentials|\/etc\/shadow|\.docker\/config\.json|\.kube\/config)/,
54
- what: "reads a credential/secret file (SSH key, cloud creds) in a filesystem-read context",
55
- },
56
- {
57
- key: "dynamic-require",
58
- severity: "medium",
59
- nearZeroFp: false,
60
- noisy: true,
61
- // require() of a DECODED/obfuscated name — NOT process.binding (legit legacy Node API in lodash/
62
- // safer-buffer/jest, often only in a comment → was a false positive).
63
- pattern: "require\\(\\s*(Buffer\\.from|atob)\\(|module\\.constructor\\._load|globalThis\\[['\"]require|require\\(\\s*_0x",
64
- re: /require\(\s*(Buffer\.from|atob)\(|module\.constructor\._load|globalThis\[['"]require|require\(\s*_0x[a-f0-9]/,
65
- what: "obfuscated module load (require of a base64/hex-decoded name)",
66
- },
67
- {
68
- key: "exfil-url",
69
- severity: "high",
70
- nearZeroFp: false,
71
- pattern: EXFIL_HOSTS,
72
- re: new RegExp(EXFIL_HOSTS, "i"),
73
- what: "beacon/exfiltration endpoint (webhook / paste / OOB-callback service)",
74
- },
75
- {
76
- key: "exfil-ip",
77
- severity: "medium", // raw-IP URLs have some legit uses (local tooling) — escalates via co-occurrence
78
- nearZeroFp: false,
79
- pattern: "https?://[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}",
80
- re: /https?:\/\/(?!127\.|0\.0\.0\.0|10\.|192\.168\.|169\.254\.|172\.(1[6-9]|2\d|3[01])\.)[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/i, // /i: rg sweeps -i; schemes are case-insensitive (an uppercase scheme prefix is a known evasion)
81
- what: "hardcoded raw-IP URL (loopback/private/link-local ranges excluded)", // 169.254.169.254 = cloud IMDS (AWS/GCP/Azure SDK metadata) — benign, was a hot FP
82
- },
83
- {
84
- key: "cloud-metadata-url",
85
- severity: "medium",
86
- nearZeroFp: false,
87
- pattern: "169\\.254\\.169\\.254|metadata\\.google\\.internal|metadata\\.azure\\.com|latest/meta-data|metadata/identity/oauth2/token|https?://metadata/computeMetadata",
88
- re: /169\.254\.169\.254|metadata\.google\.internal|metadata\.azure\.com|latest\/meta-data|metadata\/identity\/oauth2\/token|https?:\/\/metadata\/computeMetadata/i,
89
- what: "cloud metadata service URL (credential-bearing endpoint; can be legit in cloud auth code)",
90
- },
91
- {
92
- key: "network-url",
93
- severity: "low",
94
- nearZeroFp: false,
95
- noisy: true,
96
- weak: true,
97
- pattern: "(fetch|axios\\.|XMLHttpRequest|sendBeacon|https?\\.request|request\\(|curl\\b|wget\\b).{0,220}https?://",
98
- re: new RegExp(`\\b(fetch|axios\\.(get|post|put|patch|request)|XMLHttpRequest|sendBeacon|https?\\.request|http\\.request|request\\(|curl\\b|wget\\b)[\\s\\S]{0,220}?${PLAIN_EXTERNAL_URL}`, "i"),
99
- what: "network call to hardcoded external URL",
100
- },
101
- {
102
- key: "hardcoded-url",
103
- severity: "low",
104
- nearZeroFp: false,
105
- noisy: true,
106
- weak: true,
107
- pattern: "https?://",
108
- re: new RegExp(PLAIN_EXTERNAL_URL, "i"),
109
- what: "hardcoded external URL in installed package source",
110
- },
111
- {
112
- key: "env-exfil",
113
- severity: "medium",
114
- nearZeroFp: false,
115
- pattern: "JSON\\.stringify\\(process\\.env\\)|Object\\.entries\\(process\\.env\\)|dict\\(os\\.environ\\)|os\\.environ\\.copy\\(\\)|os\\.Environ\\(\\)",
116
- re: /JSON\.stringify\(process\.env\)|Object\.entries\(process\.env\)|dict\(os\.environ\)|os\.environ\.copy\(\)|os\.Environ\(\)/,
117
- what: "whole-environment serialization (secrets harvesting favorite)",
118
- },
119
- {
120
- key: "npm-token-or-publish",
121
- severity: "high",
122
- nearZeroFp: false,
123
- pattern: "NPM_TOKEN|NODE_AUTH_TOKEN|\\.npmrc|npm\\s+(publish|token)|registry\\.npmjs\\.org",
124
- re: /((NPM_TOKEN|NODE_AUTH_TOKEN|\.npmrc)[\s\S]{0,260}?(npm\s+(publish|token)|registry\.npmjs\.org)|((npm\s+(publish|token)|registry\.npmjs\.org)[\s\S]{0,260}?(NPM_TOKEN|NODE_AUTH_TOKEN|\.npmrc)))/i,
125
- what: "npm registry token/publish behavior in an installed package",
126
- },
127
- {
128
- key: "workflow-write",
129
- severity: "high",
130
- nearZeroFp: false,
131
- pattern: "\\.github/workflows|workflow_dispatch",
132
- re: /(writeFile(Sync)?|appendFile(Sync)?|copyFile(Sync)?|mkdir(Sync)?|createWriteStream|fs\.)[\s\S]{0,220}?\.github\/workflows|\.github\/workflows[\s\S]{0,220}?(writeFile(Sync)?|appendFile(Sync)?|copyFile(Sync)?|mkdir(Sync)?|createWriteStream|fs\.)/i,
133
- what: "writes GitHub Actions workflow files from a dependency",
134
- },
135
- {
136
- key: "python-obfuscated-exec",
137
- severity: "high",
138
- nearZeroFp: false,
139
- pattern: "exec\\(|eval\\(|marshal\\.loads|base64\\.b64decode|zlib\\.decompress|codecs\\.decode",
140
- re: /\b(exec|eval)\s*\(\s*(base64\.b64decode|b64decode|marshal\.loads|zlib\.decompress|codecs\.decode)\b|\bmarshal\.loads\s*\(|compile\s*\(\s*(base64\.b64decode|b64decode|zlib\.decompress|codecs\.decode)/i,
141
- what: "Python decoded/marshaled payload execution",
142
- },
143
- {
144
- key: "python-native-loader",
145
- severity: "high",
146
- nearZeroFp: false,
147
- pattern: "ctypes|VirtualAlloc|mmap\\.PROT_EXEC|CFUNCTYPE|windll\\.kernel32",
148
- re: /(ctypes|windll\.kernel32|CFUNCTYPE)[\s\S]{0,360}?(VirtualAlloc|mmap\.PROT_EXEC|memmove|CreateThread)|(VirtualAlloc|mmap\.PROT_EXEC|memmove|CreateThread)[\s\S]{0,360}?(ctypes|windll\.kernel32|CFUNCTYPE)/i,
149
- what: "Python native-memory loader pattern",
150
- },
151
- {
152
- key: "go-download-exec",
153
- severity: "high",
154
- nearZeroFp: false,
155
- pattern: "exec\\.Command|http\\.Get|http\\.Client|os\\.StartProcess",
156
- re: /(http\.(Get|Post|Client)|urlretrieve|io\.Copy)[\s\S]{0,420}?(exec\.Command|os\.StartProcess|syscall\.Exec)|(exec\.Command|os\.StartProcess|syscall\.Exec)[\s\S]{0,420}?(http\.(Get|Post|Client)|urlretrieve|io\.Copy)/i,
157
- what: "download plus process execution in Go/Python package code",
158
- },
159
- {
160
- key: "destructive-command",
161
- severity: "critical",
162
- nearZeroFp: true,
163
- pattern: "rm\\s+-rf\\s+/|mkfs\\.|dd\\s+.*of=/dev/|Remove-Item\\s+.*-Recurse|del\\s+/[sq]",
164
- re: /\brm\s+-rf\s+\/(?:\s|$)|\bmkfs\.[a-z0-9]+\b|\bdd\s+[^\n]*(of=\/dev\/(sd|hd|vd|nvme|disk)|if=\/dev\/zero)|Remove-Item\s+[^\n]*-Recurse|\bdel\s+\/[sq]\b/i,
165
- what: "destructive filesystem command embedded in a dependency",
166
- },
167
- {
168
- key: "crypto-clipper",
169
- severity: "high",
170
- nearZeroFp: false,
171
- pattern: "clipboard|writeText|execCommand\\(['\"]copy|bc1[a-z0-9]{11}|0x[a-fA-F0-9]{40}",
172
- re: /(clipboard|writeText|execCommand\(['"]copy|clipboardy)[\s\S]{0,520}?\b(0x[a-fA-F0-9]{40}|bc1[ac-hj-np-z02-9]{11,71}|[13][a-km-zA-HJ-NP-Z1-9]{25,34})\b|\b(0x[a-fA-F0-9]{40}|bc1[ac-hj-np-z02-9]{11,71}|[13][a-km-zA-HJ-NP-Z1-9]{25,34})\b[\s\S]{0,520}?(clipboard|writeText|execCommand\(['"]copy|clipboardy)/i,
173
- what: "clipboard rewrite paired with a cryptocurrency wallet address",
174
- },
175
- {
176
- key: "hidden-unicode",
177
- severity: "medium",
178
- nearZeroFp: false,
179
- pattern: "[\\x{202A}-\\x{202E}\\x{2066}-\\x{2069}]",
180
- re: new RegExp("\\u202A|\\u202B|\\u202C|\\u202D|\\u202E|\\u2066|\\u2067|\\u2068|\\u2069", "u"),
181
- what: "hidden bidirectional Unicode control character in package source",
182
- },
183
- {
184
- key: "obfuscated-code",
185
- severity: "low", // minified/legit code look-alikes — only escalates with a second signal
186
- nearZeroFp: false,
187
- noisy: true,
188
- pattern: "eval\\(atob\\(|eval\\(Buffer\\.from\\(|\\b_0x[a-f0-9]{4,}\\b",
189
- re: /eval\(atob\(|eval\(Buffer\.from\([^)]*base64|\b_0x[a-f0-9]{4,}\b/,
190
- what: "obfuscation marker (eval-of-decoded payload / string-array obfuscator)",
191
- },
192
- ];
@@ -1,60 +0,0 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { createRepoBoundary } from "../repo-path.js";
3
-
4
- const REPORT_PATHS = [
5
- ".weavatrix/reports/cargo-audit.json",
6
- ".weavatrix/cargo-audit.json",
7
- "cargo-audit.json",
8
- ];
9
-
10
- const warningEntries = (warnings) => Object.entries(warnings || {}).flatMap(([kind, value]) =>
11
- (Array.isArray(value) ? value : value?.list || []).map((item) => ({ kind, ...item })));
12
-
13
- // Imports an explicitly generated `cargo audit --json` report. Core never runs Cargo, downloads the
14
- // RustSec database, or executes repository code; an absent/stale report remains visibly incomplete.
15
- export function loadRustAdvisoryReport(repoPath, { now = Date.now(), maxAgeDays = 30 } = {}) {
16
- const boundary = createRepoBoundary(repoPath);
17
- if (!boundary.root) return { status: "ERROR", detail: "Repository boundary is unavailable.", findings: [] };
18
- const found = REPORT_PATHS.map((file) => ({ file, resolved: boundary.resolve(file) }))
19
- .find((item) => item.resolved.ok && existsSync(item.resolved.path));
20
- if (!found) return {
21
- status: "NOT_CHECKED",
22
- detail: "No saved cargo audit --json report was found; Cargo.lock OSV matching is separate evidence.",
23
- findings: [],
24
- };
25
- try {
26
- const report = JSON.parse(readFileSync(found.resolved.path, "utf8"));
27
- const vulnerabilities = report?.vulnerabilities?.list;
28
- if (!Array.isArray(vulnerabilities)) throw new Error("vulnerabilities.list is missing");
29
- const checkedAt = report?.database?.["last-updated"] || report?.database?.lastUpdated || report?.generatedAt || null;
30
- const ageMs = checkedAt ? now - new Date(checkedAt).getTime() : Number.POSITIVE_INFINITY;
31
- const stale = !Number.isFinite(ageMs) || ageMs > maxAgeDays * 86_400_000;
32
- const findings = vulnerabilities.map((item) => ({
33
- kind: "vulnerability",
34
- id: item.advisory?.id || "RUSTSEC-UNKNOWN",
35
- title: item.advisory?.title || item.advisory?.description || "RustSec advisory",
36
- url: item.advisory?.url || "",
37
- package: item.package?.name || item.advisory?.package || "unknown-crate",
38
- version: item.package?.version || "",
39
- patched: item.versions?.patched || [],
40
- }));
41
- findings.push(...warningEntries(report?.warnings).map((item) => ({
42
- kind: item.kind || "warning",
43
- id: item.advisory?.id || `cargo-audit-${item.kind || "warning"}`,
44
- title: item.advisory?.title || item.message || `Cargo audit ${item.kind || "warning"}`,
45
- url: item.advisory?.url || "",
46
- package: item.package?.name || item.advisory?.package || "unknown-crate",
47
- version: item.package?.version || "",
48
- patched: item.versions?.patched || [],
49
- })));
50
- return {
51
- status: stale ? "PARTIAL" : "OK",
52
- detail: `${stale ? "Imported stale/undated" : "Imported"} cargo-audit report ${found.file}: ${vulnerabilities.length} vulnerability/vulnerabilities and ${findings.length - vulnerabilities.length} warning(s).`,
53
- checkedAt,
54
- file: found.file,
55
- findings,
56
- };
57
- } catch (error) {
58
- return { status: "ERROR", detail: `Could not read ${found.file}: ${error instanceof Error ? error.message : String(error)}`, file: found.file, findings: [] };
59
- }
60
- }
@@ -1,81 +0,0 @@
1
- // Typosquat / name-confusion detection: is a package name a near-miss of a popular one (a classic
2
- // supply-chain lure — crossenv↔cross-env, lodahs↔lodash)? Damerau-Levenshtein (handles transposition)
3
- // against a bundled top-package list. Deliberately LOW-FP: many legit packages sit distance-1 from a
4
- // popular one, so the caller GATES this — transitive deps only surface when a second malware signal
5
- // co-fires (scanMalware), direct deps surface quietly at info level. DEPS_SECURITY_PLAN P6.
6
-
7
- // Popular + historically-typosquatted npm names. Not exhaustive — the high-value lure targets.
8
- export const TOP_PACKAGES = new Set([
9
- "react", "react-dom", "lodash", "express", "axios", "chalk", "commander", "debug", "moment", "dayjs",
10
- "webpack", "babel", "eslint", "prettier", "typescript", "jest", "mocha", "chai", "vue", "angular",
11
- "next", "nuxt", "svelte", "vite", "rollup", "esbuild", "dotenv", "cors", "body-parser", "mongoose",
12
- "mongodb", "mysql", "mysql2", "pg", "redis", "ioredis", "sequelize", "knex", "prisma", "socket.io",
13
- "ws", "node-fetch", "got", "request", "superagent", "cross-env", "cross-spawn", "rimraf", "glob",
14
- "fs-extra", "chokidar", "nodemon", "concurrently", "husky", "lint-staged", "uuid", "nanoid", "bcrypt",
15
- "bcryptjs", "jsonwebtoken", "passport", "joi", "yup", "zod", "ajv", "classnames", "styled-components",
16
- "tailwindcss", "postcss", "autoprefixer", "sass", "less", "react-router", "react-router-dom", "redux",
17
- "react-redux", "@reduxjs/toolkit", "mobx", "recoil", "zustand", "formik", "react-hook-form", "immer",
18
- "rxjs", "date-fns", "ramda", "underscore", "immutable", "yargs", "inquirer", "ora", "boxen", "chalk",
19
- "colors", "winston", "pino", "morgan", "helmet", "compression", "cookie-parser", "express-session",
20
- "multer", "sharp", "jimp", "puppeteer", "playwright", "cypress", "supertest", "sinon", "nock",
21
- "ts-node", "tslib", "core-js", "regenerator-runtime", "@babel/core", "babel-loader", "css-loader",
22
- "style-loader", "html-webpack-plugin", "terser", "browserify", "gulp", "grunt", "electron", "three",
23
- "d3", "chart.js", "echarts", "leaflet", "mapbox-gl", "graphql", "apollo-server", "@apollo/client",
24
- "protobufjs", "grpc", "kafkajs", "amqplib", "bull", "node-cron", "cheerio", "jsdom", "marked",
25
- "markdown-it", "highlight.js", "prismjs", "qs", "querystring", "form-data", "semver", "minimist",
26
- ]);
27
-
28
- // Legit close pairs to NOT flag (real distinct packages that happen to sit distance-1/2 apart).
29
- const KNOWN_LEGIT = new Set([
30
- "cross-spawn", "react-dom", "react-router", "bcryptjs", "mysql2", "colors", "underscore", "querystring",
31
- "markdown-it", "babel-loader", "css-loader", "style-loader", "query-string",
32
- ]);
33
-
34
- const rawName = (name) => String(name || "").trim().toLowerCase();
35
- const isScoped = (name) => /^@[^/]+\/.+/.test(name);
36
- const unscopedTail = (name) => name.replace(/^@[^/]+\//, "");
37
-
38
- // Damerau-Levenshtein (optimal string alignment) — includes adjacent transposition.
39
- export function damerau(a, b) {
40
- a = String(a); b = String(b);
41
- const m = a.length, n = b.length;
42
- if (!m) return n;
43
- if (!n) return m;
44
- const d = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
45
- for (let i = 0; i <= m; i++) d[i][0] = i;
46
- for (let j = 0; j <= n; j++) d[0][j] = j;
47
- for (let i = 1; i <= m; i++) {
48
- for (let j = 1; j <= n; j++) {
49
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
50
- d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
51
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
52
- }
53
- }
54
- return d[m][n];
55
- }
56
-
57
- // → { nearest, distance } if `name` looks like a typosquat of a popular package, else null.
58
- // Threshold: distance 1 always; distance 2 only for names ≥8 chars (short names collide too easily).
59
- // Skip: exact popular names, known-legit pairs, names <4 chars.
60
- export function classifyTyposquat(name) {
61
- const raw = rawName(name);
62
- const scoped = isScoped(raw);
63
- const tail = unscopedTail(raw);
64
- // A package scope is an ownership boundary, not punctuation to discard.
65
- // Comparing every scoped basename with unscoped popular names made the
66
- // official @playwright/test package look like a one-edit misspelling of jest.
67
- if (tail.length < 4 || TOP_PACKAGES.has(raw) || TOP_PACKAGES.has(tail)
68
- || KNOWN_LEGIT.has(raw) || KNOWN_LEGIT.has(tail)) return null;
69
- const candidates = [...TOP_PACKAGES].filter((top) => isScoped(top) === scoped);
70
- const n = scoped ? raw : tail;
71
- let best = null;
72
- for (const top of candidates) {
73
- const t = rawName(top);
74
- if (t === n) return null; // scope-only difference of a popular name → not a squat
75
- const dist = damerau(n, t);
76
- if (dist === 0) return null;
77
- const limit = t.length >= 8 ? 2 : 1;
78
- if (dist <= limit && (!best || dist < best.distance)) best = { nearest: top, distance: dist };
79
- }
80
- return best;
81
- }
package/src/util.js DELETED
@@ -1,40 +0,0 @@
1
- // Shared fs/text helpers.
2
- import { readFileSync, statSync } from "node:fs";
3
-
4
- // Bounded, never-throwing file read shared by the source scanners (infra, endpoints): oversized
5
- // files are skipped, not truncated — a partial read would produce misleading matches.
6
- export const MAX_FILE_BYTES = 512 * 1024;
7
-
8
- // Order-preserving dedupe by a derived key — first occurrence wins.
9
- export function uniqueBy(list, keyFn) {
10
- const seen = new Set();
11
- return list.filter((item) => {
12
- const k = keyFn(item);
13
- if (seen.has(k)) return false;
14
- seen.add(k);
15
- return true;
16
- });
17
- }
18
-
19
- export function lineNumberAt(text, index) {
20
- let line = 1;
21
- for (let offset = 0; offset < index && offset < text.length; offset++) {
22
- if (text[offset] === "\n") line++;
23
- }
24
- return line;
25
- }
26
-
27
- export function boundedInteger(value, fallback, min, max) {
28
- const number = Number(value);
29
- return Number.isInteger(number) ? Math.max(min, Math.min(max, number)) : fallback;
30
- }
31
-
32
- export function safeRead(path) {
33
- try {
34
- const st = statSync(path);
35
- if (!st.isFile() || st.size > MAX_FILE_BYTES) return "";
36
- return readFileSync(path, "utf8");
37
- } catch {
38
- return "";
39
- }
40
- }
package/src/version.js DELETED
@@ -1,7 +0,0 @@
1
- import {createRequire} from 'node:module'
2
-
3
- const requireFromWeavatrix = createRequire(import.meta.url)
4
-
5
- export const WEAVATRIX_VERSION = String(
6
- requireFromWeavatrix('../package.json').version || 'unknown',
7
- )