weavatrix 0.3.14 → 1.1.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 (306) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +132 -200
  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 +10 -67
  14. package/server.json +38 -0
  15. package/skill/SKILL.md +62 -374
  16. package/skill/agents/openai.yaml +4 -0
  17. package/skill/references/tool-routing.md +45 -0
  18. package/SECURITY.md +0 -101
  19. package/docs/adr/0001-v0.3-offline-online-split.md +0 -60
  20. package/docs/agent-task-benchmark.md +0 -58
  21. package/docs/releases/v0.2.19.md +0 -33
  22. package/docs/releases/v0.3.0.md +0 -43
  23. package/docs/releases/v0.3.1.md +0 -30
  24. package/docs/releases/v0.3.10.md +0 -76
  25. package/docs/releases/v0.3.11.md +0 -55
  26. package/docs/releases/v0.3.12.md +0 -44
  27. package/docs/releases/v0.3.13.md +0 -34
  28. package/docs/releases/v0.3.14.md +0 -37
  29. package/docs/releases/v0.3.2.md +0 -15
  30. package/docs/releases/v0.3.3.md +0 -25
  31. package/docs/releases/v0.3.4.md +0 -40
  32. package/docs/releases/v0.3.5.md +0 -50
  33. package/docs/releases/v0.3.6.md +0 -44
  34. package/docs/releases/v0.3.7.md +0 -37
  35. package/docs/releases/v0.3.8.md +0 -21
  36. package/docs/releases/v0.3.9.md +0 -36
  37. package/scripts/run-agent-task-benchmark.mjs +0 -118
  38. package/src/analysis/allowed-test-runner.js +0 -70
  39. package/src/analysis/architecture/contract-graph.js +0 -119
  40. package/src/analysis/architecture/contract-schema.js +0 -110
  41. package/src/analysis/architecture/contract-storage.js +0 -35
  42. package/src/analysis/architecture/contract-verification.js +0 -168
  43. package/src/analysis/architecture-contract.js +0 -16
  44. package/src/analysis/audit-debt.js +0 -94
  45. package/src/analysis/audit-extensions.js +0 -60
  46. package/src/analysis/cargo-dependency-evidence.js +0 -108
  47. package/src/analysis/cargo-manifests.js +0 -81
  48. package/src/analysis/change-classification/diff-parser.js +0 -103
  49. package/src/analysis/change-classification/options.js +0 -40
  50. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  51. package/src/analysis/change-classification.js +0 -188
  52. package/src/analysis/coverage-reports-tarpaulin.js +0 -112
  53. package/src/analysis/coverage-reports.js +0 -246
  54. package/src/analysis/cycle-route.js +0 -14
  55. package/src/analysis/data-flow-evidence.js +0 -114
  56. package/src/analysis/dead-check.js +0 -300
  57. package/src/analysis/dead-code-review/candidates.js +0 -194
  58. package/src/analysis/dead-code-review/policy.js +0 -23
  59. package/src/analysis/dead-code-review.js +0 -119
  60. package/src/analysis/dep-check-ecosystems.js +0 -205
  61. package/src/analysis/dep-check.js +0 -290
  62. package/src/analysis/dep-rules.js +0 -10
  63. package/src/analysis/dependency/conventions.js +0 -16
  64. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  65. package/src/analysis/dependency/source-references.js +0 -21
  66. package/src/analysis/duplicate-groups.js +0 -104
  67. package/src/analysis/duplicates-worker.js +0 -11
  68. package/src/analysis/duplicates.compute.js +0 -269
  69. package/src/analysis/duplicates.js +0 -15
  70. package/src/analysis/duplicates.run.js +0 -52
  71. package/src/analysis/duplicates.tokenize.js +0 -199
  72. package/src/analysis/endpoints/common.js +0 -79
  73. package/src/analysis/endpoints/extract.js +0 -120
  74. package/src/analysis/endpoints/inventory.js +0 -84
  75. package/src/analysis/endpoints/mounts.js +0 -129
  76. package/src/analysis/endpoints-java.js +0 -260
  77. package/src/analysis/endpoints-rust.js +0 -124
  78. package/src/analysis/endpoints.js +0 -3
  79. package/src/analysis/findings.js +0 -70
  80. package/src/analysis/git-history/analytics.js +0 -177
  81. package/src/analysis/git-history/collector.js +0 -67
  82. package/src/analysis/git-history/options.js +0 -66
  83. package/src/analysis/git-history.js +0 -143
  84. package/src/analysis/git-ref-graph.js +0 -76
  85. package/src/analysis/go-dependency-evidence.js +0 -62
  86. package/src/analysis/graph-analysis.aggregate.js +0 -296
  87. package/src/analysis/graph-analysis.edges.js +0 -24
  88. package/src/analysis/graph-analysis.js +0 -7
  89. package/src/analysis/graph-analysis.refs.js +0 -202
  90. package/src/analysis/graph-analysis.summaries.js +0 -65
  91. package/src/analysis/health-capabilities.js +0 -83
  92. package/src/analysis/hot-path-review.js +0 -266
  93. package/src/analysis/http-contract-wrappers.js +0 -241
  94. package/src/analysis/http-contracts/analysis.js +0 -179
  95. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  96. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  97. package/src/analysis/http-contracts/graph-context.js +0 -143
  98. package/src/analysis/http-contracts/matching.js +0 -61
  99. package/src/analysis/http-contracts/shared.js +0 -85
  100. package/src/analysis/http-contracts.js +0 -6
  101. package/src/analysis/internal-audit/dependency-health.js +0 -113
  102. package/src/analysis/internal-audit/python-manifests.js +0 -78
  103. package/src/analysis/internal-audit/repo-files.js +0 -50
  104. package/src/analysis/internal-audit/supply-chain.js +0 -149
  105. package/src/analysis/internal-audit.collect.js +0 -213
  106. package/src/analysis/internal-audit.js +0 -9
  107. package/src/analysis/internal-audit.reach.js +0 -201
  108. package/src/analysis/internal-audit.run.js +0 -256
  109. package/src/analysis/java-source.js +0 -36
  110. package/src/analysis/jvm-artifact-index.js +0 -87
  111. package/src/analysis/jvm-dependency-evidence.js +0 -138
  112. package/src/analysis/jvm-manifests.js +0 -114
  113. package/src/analysis/manifests.js +0 -123
  114. package/src/analysis/package-reachability.js +0 -39
  115. package/src/analysis/source-complexity.ast.js +0 -97
  116. package/src/analysis/source-complexity.constants.js +0 -55
  117. package/src/analysis/source-complexity.js +0 -14
  118. package/src/analysis/source-complexity.report.js +0 -81
  119. package/src/analysis/source-complexity.walk.js +0 -228
  120. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  121. package/src/analysis/source-correctness.js +0 -222
  122. package/src/analysis/static-test-reachability.js +0 -150
  123. package/src/analysis/structure/dependency-graph.js +0 -151
  124. package/src/analysis/structure/findings.js +0 -162
  125. package/src/analysis/task-retrieval.js +0 -107
  126. package/src/analysis/transport-contracts.js +0 -224
  127. package/src/analysis/transport-runtime-evidence.js +0 -155
  128. package/src/analysis-kit.mjs +0 -17
  129. package/src/bounds.js +0 -4
  130. package/src/build-graph.js +0 -209
  131. package/src/child-env.js +0 -7
  132. package/src/config.js +0 -5
  133. package/src/extension/local-services.mjs +0 -75
  134. package/src/git-exec.js +0 -67
  135. package/src/graph/build-worker.js +0 -49
  136. package/src/graph/builder/go-receiver-resolution.js +0 -112
  137. package/src/graph/builder/js/dynamic-import.js +0 -26
  138. package/src/graph/builder/js/queries.js +0 -48
  139. package/src/graph/builder/lang-csharp.js +0 -40
  140. package/src/graph/builder/lang-css.js +0 -29
  141. package/src/graph/builder/lang-go.js +0 -140
  142. package/src/graph/builder/lang-html.js +0 -29
  143. package/src/graph/builder/lang-java-calls.js +0 -142
  144. package/src/graph/builder/lang-java.js +0 -215
  145. package/src/graph/builder/lang-js.js +0 -291
  146. package/src/graph/builder/lang-python.js +0 -235
  147. package/src/graph/builder/lang-rust-calls.js +0 -63
  148. package/src/graph/builder/lang-rust.js +0 -299
  149. package/src/graph/builder/lang-solidity.js +0 -126
  150. package/src/graph/builder/lang-sql.js +0 -263
  151. package/src/graph/builder/pass2-resolution.js +0 -81
  152. package/src/graph/builder/spec-pkg.js +0 -87
  153. package/src/graph/community.js +0 -27
  154. package/src/graph/edge-provenance.js +0 -31
  155. package/src/graph/file-lock.js +0 -69
  156. package/src/graph/freshness-probe.js +0 -142
  157. package/src/graph/graph-filter.js +0 -63
  158. package/src/graph/incremental-refresh.js +0 -235
  159. package/src/graph/internal-builder.barrels.js +0 -235
  160. package/src/graph/internal-builder.build.js +0 -300
  161. package/src/graph/internal-builder.java.js +0 -33
  162. package/src/graph/internal-builder.js +0 -12
  163. package/src/graph/internal-builder.langs.js +0 -157
  164. package/src/graph/internal-builder.pass2.js +0 -163
  165. package/src/graph/internal-builder.resolvers.js +0 -286
  166. package/src/graph/layout.js +0 -51
  167. package/src/graph/node-id.js +0 -7
  168. package/src/graph/parser-artifact-boundary.js +0 -55
  169. package/src/graph/relations.js +0 -4
  170. package/src/graph/repo-registry.js +0 -124
  171. package/src/graph/resolvers/rust.js +0 -117
  172. package/src/infra/infra-items.js +0 -255
  173. package/src/infra/infra-registry.js +0 -184
  174. package/src/infra/infra.detect.js +0 -119
  175. package/src/infra/infra.js +0 -38
  176. package/src/infra/infra.match.js +0 -102
  177. package/src/infra/infra.scan.js +0 -93
  178. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  179. package/src/mcp/architecture-bootstrap.mjs +0 -168
  180. package/src/mcp/architecture-starter.mjs +0 -234
  181. package/src/mcp/catalog.mjs +0 -233
  182. package/src/mcp/company-contract-page.mjs +0 -142
  183. package/src/mcp/company-contract-reconcile.mjs +0 -87
  184. package/src/mcp/company-contract-verdict.mjs +0 -42
  185. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  186. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  187. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  188. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  189. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  190. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  191. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  192. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  193. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  194. package/src/mcp/evidence-snapshot.mjs +0 -50
  195. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  196. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  197. package/src/mcp/extension-api.mjs +0 -77
  198. package/src/mcp/git-output.mjs +0 -7
  199. package/src/mcp/graph/context-core.mjs +0 -111
  200. package/src/mcp/graph/context-seeds.mjs +0 -207
  201. package/src/mcp/graph/context-state.mjs +0 -85
  202. package/src/mcp/graph/reverse-reach.mjs +0 -42
  203. package/src/mcp/graph/tools-core.mjs +0 -143
  204. package/src/mcp/graph/tools-query.mjs +0 -276
  205. package/src/mcp/graph-context.mjs +0 -5
  206. package/src/mcp/graph-diff.mjs +0 -218
  207. package/src/mcp/health/audit-format.mjs +0 -199
  208. package/src/mcp/health/audit.mjs +0 -199
  209. package/src/mcp/health/dead-code.mjs +0 -110
  210. package/src/mcp/health/duplicates.mjs +0 -121
  211. package/src/mcp/health/endpoints.mjs +0 -71
  212. package/src/mcp/health/structure.mjs +0 -220
  213. package/src/mcp/runtime-version.mjs +0 -31
  214. package/src/mcp/server/auto-refresh.mjs +0 -66
  215. package/src/mcp/server/runtime-config.mjs +0 -43
  216. package/src/mcp/server/shutdown.mjs +0 -40
  217. package/src/mcp/staleness-notice.mjs +0 -20
  218. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  219. package/src/mcp/sync/evidence-common.mjs +0 -88
  220. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  221. package/src/mcp/sync/evidence-health.mjs +0 -56
  222. package/src/mcp/sync/evidence-packages.mjs +0 -95
  223. package/src/mcp/sync/payload-common.mjs +0 -97
  224. package/src/mcp/sync/payload-v2.mjs +0 -54
  225. package/src/mcp/sync/payload-v3.mjs +0 -79
  226. package/src/mcp/sync-evidence.mjs +0 -23
  227. package/src/mcp/sync-payload.mjs +0 -70
  228. package/src/mcp/tool-result.mjs +0 -54
  229. package/src/mcp/tools-actions.mjs +0 -11
  230. package/src/mcp/tools-architecture.mjs +0 -177
  231. package/src/mcp/tools-company.mjs +0 -251
  232. package/src/mcp/tools-context.mjs +0 -222
  233. package/src/mcp/tools-endpoints.mjs +0 -207
  234. package/src/mcp/tools-graph-hubs.mjs +0 -78
  235. package/src/mcp/tools-graph.mjs +0 -17
  236. package/src/mcp/tools-health.mjs +0 -24
  237. package/src/mcp/tools-history.mjs +0 -28
  238. package/src/mcp/tools-impact-change.mjs +0 -220
  239. package/src/mcp/tools-impact-precision.mjs +0 -89
  240. package/src/mcp/tools-impact.mjs +0 -169
  241. package/src/mcp/tools-source.mjs +0 -238
  242. package/src/mcp/tools-verified-change.mjs +0 -200
  243. package/src/mcp-rg.mjs +0 -50
  244. package/src/mcp-runtime.mjs +0 -2
  245. package/src/mcp-server.mjs +0 -298
  246. package/src/mcp-source-tools.mjs +0 -163
  247. package/src/path-classification.js +0 -226
  248. package/src/path-ignore.js +0 -69
  249. package/src/precision/lsp-client/constants.js +0 -12
  250. package/src/precision/lsp-client/environment.js +0 -20
  251. package/src/precision/lsp-client/errors.js +0 -15
  252. package/src/precision/lsp-client/lifecycle.js +0 -114
  253. package/src/precision/lsp-client/message-parser.js +0 -81
  254. package/src/precision/lsp-client/protocol.js +0 -212
  255. package/src/precision/lsp-client/registry.js +0 -59
  256. package/src/precision/lsp-client/repo-uri.js +0 -60
  257. package/src/precision/lsp-client/stdio-client.js +0 -140
  258. package/src/precision/lsp-client.js +0 -10
  259. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  260. package/src/precision/lsp-overlay/build.js +0 -261
  261. package/src/precision/lsp-overlay/contract.js +0 -61
  262. package/src/precision/lsp-overlay/reference-results.js +0 -108
  263. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  264. package/src/precision/lsp-overlay/source-session.js +0 -142
  265. package/src/precision/lsp-overlay/store.js +0 -150
  266. package/src/precision/lsp-overlay/target-index.js +0 -152
  267. package/src/precision/lsp-overlay/target-query.js +0 -55
  268. package/src/precision/lsp-overlay.js +0 -11
  269. package/src/precision/symbol-query.js +0 -224
  270. package/src/precision/typescript-lsp-provider.js +0 -12
  271. package/src/precision/typescript-provider/client.js +0 -89
  272. package/src/precision/typescript-provider/discovery.js +0 -124
  273. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  274. package/src/precision/typescript-provider/project-host.js +0 -254
  275. package/src/precision/typescript-provider/project-safety.js +0 -166
  276. package/src/precision/typescript-provider/reference-usage.js +0 -53
  277. package/src/process.js +0 -95
  278. package/src/repo-path.js +0 -53
  279. package/src/scan/discover.inventory.js +0 -78
  280. package/src/scan/discover.js +0 -5
  281. package/src/scan/discover.list.js +0 -79
  282. package/src/scan/discover.stack.js +0 -227
  283. package/src/scan/search.core.js +0 -24
  284. package/src/scan/search.git.js +0 -102
  285. package/src/scan/search.js +0 -9
  286. package/src/scan/search.node.js +0 -83
  287. package/src/scan/search.preview.js +0 -49
  288. package/src/scan/search.rg.js +0 -145
  289. package/src/security/advisory-store.js +0 -172
  290. package/src/security/installed-jvm-rust.js +0 -46
  291. package/src/security/installed.js +0 -280
  292. package/src/security/malware-file-heuristics.js +0 -121
  293. package/src/security/malware-heuristics.exclusions.js +0 -134
  294. package/src/security/malware-heuristics.js +0 -15
  295. package/src/security/malware-heuristics.roots.js +0 -145
  296. package/src/security/malware-heuristics.scan.js +0 -89
  297. package/src/security/malware-heuristics.sweep.js +0 -122
  298. package/src/security/malware-scoring.js +0 -105
  299. package/src/security/match.js +0 -85
  300. package/src/security/registry-sig.classify.js +0 -137
  301. package/src/security/registry-sig.js +0 -18
  302. package/src/security/registry-sig.rules.js +0 -192
  303. package/src/security/rust-advisory-report.js +0 -60
  304. package/src/security/typosquat.js +0 -81
  305. package/src/util.js +0 -40
  306. package/src/version.js +0 -7
@@ -1,280 +0,0 @@
1
- // Installed-package enumeration for supply-chain scanning: EXACT versions from lockfiles first
2
- // (package-lock v1/v2/v3, basic yarn.lock, requirements.txt ==pins, go.sum), plus a top-level
3
- // node_modules walk — which also yields the lockfile-DRIFT signal (installed ≠ locked → tampering or
4
- // stale install). Parsers are pure + exported for tests; collectInstalled is the thin fs wrapper.
5
- import { readFileSync, readdirSync } from "node:fs";
6
- import { join, relative } from "node:path";
7
- import { parseGoMod } from "../analysis/manifests.js";
8
- import { uniqueBy } from "../util.js";
9
- import { createRepoBoundary } from "../repo-path.js";
10
- import { collectJvmRustInstalled } from "./installed-jvm-rust.js";
11
- import { listRepoFiles, readRepoText } from "../analysis/internal-audit/repo-files.js";
12
-
13
- const pep503 = (name) => String(name).toLowerCase().replace(/[-_.]+/g, "-"); // PyPI canonical name
14
-
15
- const dedupe = (list) => uniqueBy(list, (p) => `${p.ecosystem}|${p.name}|${p.version}`);
16
-
17
- export function parsePackageLock(json) {
18
- const out = [];
19
- const lockTracksScripts = Number(json?.lockfileVersion || 0) >= 2;
20
- if (json && json.packages && typeof json.packages === "object") { // v2/v3
21
- for (const [key, v] of Object.entries(json.packages)) {
22
- if (!key.startsWith("node_modules/") || !v || !v.version) continue;
23
- const name = key.slice(key.lastIndexOf("node_modules/") + "node_modules/".length); // nested a/node_modules/b → b
24
- if (!name || name.startsWith(".")) continue;
25
- const depth = key.split("node_modules/").length - 1; // 1 = hoisted top-level, 2+ = nested duplicate
26
- out.push({ ecosystem: "npm", name, version: v.version, dev: !!v.dev, integrity: v.integrity || "", resolved: v.resolved || "", source: "package-lock", depth, hasInstallScript: lockTracksScripts ? !!v.hasInstallScript : undefined });
27
- }
28
- } else if (json && json.dependencies) { // v1 recursive tree
29
- const walk = (deps, depth) => {
30
- for (const [name, v] of Object.entries(deps || {})) {
31
- if (v && v.version) out.push({ ecosystem: "npm", name, version: v.version, dev: !!v.dev, integrity: v.integrity || "", source: "package-lock", depth });
32
- if (v && v.dependencies) walk(v.dependencies, depth + 1);
33
- }
34
- };
35
- walk(json.dependencies, 1);
36
- }
37
- return dedupe(out);
38
- }
39
-
40
- // yarn.lock selector → the REAL package name. Handles classic `name@range`, `@scope/name@range`, the
41
- // `@npm:` protocol (`name@npm:range`), AND aliases (`react-is-18@npm:react-is@18.3.1` → react-is) —
42
- // yarn installs aliased majors in `react-is-18/` dirs whose package.json name is still "react-is", so
43
- // the lockfile must resolve to that real name or drift/vuln checks miss the aliased versions.
44
- export function yarnSelectorName(sel) {
45
- const s = String(sel || "").trim().replace(/^"|"$/g, "");
46
- const npm = s.indexOf("@npm:");
47
- if (npm >= 0) {
48
- const after = s.slice(npm + 5); // text after "@npm:" — either "realname@range" (alias) or just "range"
49
- if (/^[a-z@]/i.test(after)) { // starts with a letter/scope → it's the real package name
50
- const at = after.startsWith("@") ? after.indexOf("@", 1) : after.indexOf("@");
51
- return at > 0 ? after.slice(0, at) : after;
52
- }
53
- return s.slice(0, npm); // "range" only → the real name is before @npm:
54
- }
55
- const at = s.lastIndexOf("@"); // classic name@range ; leading @ of a scope is index 0, ignored
56
- return at > 0 ? s.slice(0, at) : "";
57
- }
58
-
59
- // yarn.lock (classic v1 format): `"name@^1.0.0", "name@~1.2":\n version "1.2.3"`
60
- export function parseYarnLock(text) {
61
- const out = [];
62
- const re = /^((?:"[^\n]*")|(?:[^\s#"][^\n]*?)):\r?\n\s+version\s+"([^"]+)"/gm; // greedy quote span — selector lists like "a@^1", "a@~2": keep the full line
63
- for (const m of String(text || "").matchAll(re)) {
64
- const name = yarnSelectorName(m[1].split(",")[0]);
65
- if (name) out.push({ ecosystem: "npm", name, version: m[2], dev: false, integrity: "", source: "yarn-lock" });
66
- }
67
- return dedupe(out);
68
- }
69
-
70
- // requirements.txt: pins that carry a concrete version — exact `==`/`===` AND compatible-release `~=`
71
- // (`~=1.26.8` floors at 1.26.8 within the 1.26.* series, a solid check target). Loose `>=`/`>`/`<`
72
- // have no single version, so they're skipped (unknown-installed, not a false pin).
73
- export function parseRequirements(text) {
74
- const out = [];
75
- for (const raw of String(text || "").split(/\r?\n/)) {
76
- const line = raw.replace(/(^|\s)#.*$/, "").trim();
77
- if (!line || line.startsWith("-")) continue;
78
- const m = line.match(/^([A-Za-z0-9][\w.-]*)\s*(===?|~=)\s*([\w.!+*-]+)/);
79
- if (m) out.push({ ecosystem: "PyPI", name: pep503(m[1]), version: String(m[3]).replace(/\.\*$/, ""), dev: false, integrity: "", source: "requirements" });
80
- }
81
- return dedupe(out);
82
- }
83
-
84
- // A repo's virtualenv site-packages *.dist-info = the ACTUALLY-installed Python versions (the PyPI
85
- // equivalent of node_modules). Directory names are "<name>-<version>.dist-info". Windows Lib\ + posix lib\pythonX\.
86
- export function collectVenvPackages(repoPath, { readdir = readdirSync } = {}) {
87
- const out = [];
88
- for (const venv of [".venv", "venv", "env"]) {
89
- const roots = [join(repoPath, venv, "Lib", "site-packages")]; // Windows layout
90
- try { for (const d of readdir(join(repoPath, venv, "lib"))) if (/^python/i.test(String(d))) roots.push(join(repoPath, venv, "lib", String(d), "site-packages")); } catch { /* posix layout absent */ }
91
- for (const sp of roots) {
92
- let entries;
93
- try { entries = readdir(sp); } catch { continue; }
94
- for (const e of entries) {
95
- const m = String(e).match(/^(.+?)-(\d[\w.!+-]*)\.dist-info$/);
96
- if (m) out.push({ ecosystem: "PyPI", name: pep503(m[1]), version: m[2], dev: false, integrity: "", source: "venv" });
97
- }
98
- }
99
- }
100
- return dedupe(out);
101
- }
102
-
103
- // poetry.lock / uv.lock — same TOML shape: [[package]] blocks with name/version lines
104
- export function parseTomlLockPackages(text, source) {
105
- const out = [];
106
- let name = "", inPkg = false;
107
- for (const raw of String(text || "").split(/\r?\n/)) {
108
- const line = raw.trim();
109
- if (/^\[\[package\]\]$/.test(line)) { inPkg = true; name = ""; continue; }
110
- if (/^\[/.test(line)) { inPkg = false; continue; } // any other table ends the package header block
111
- if (!inPkg) continue;
112
- let m = line.match(/^name\s*=\s*"([^"]+)"/);
113
- if (m) { name = m[1]; continue; }
114
- m = line.match(/^version\s*=\s*"([^"]+)"/);
115
- if (m && name) { out.push({ ecosystem: "PyPI", name: pep503(name), version: m[1], dev: false, integrity: "", source }); name = ""; }
116
- }
117
- return dedupe(out);
118
- }
119
-
120
- // Pipfile.lock: JSON { default: { name: {version:"==1.2.3"} }, develop: {…} }
121
- export function parsePipfileLock(json) {
122
- const out = [];
123
- for (const [section, dev] of [["default", false], ["develop", true]]) {
124
- for (const [name, v] of Object.entries((json && json[section]) || {})) {
125
- const ver = String((v && v.version) || "").replace(/^==/, "");
126
- if (ver) out.push({ ecosystem: "PyPI", name: pep503(name), version: ver, dev, integrity: "", source: "pipfile-lock" });
127
- }
128
- }
129
- return dedupe(out);
130
- }
131
-
132
- // go.sum: "module v1.2.3 h1:hash" (skip /go.mod hash lines). OSV Go versions have no leading v.
133
- export function parseGoSum(text) {
134
- const out = [];
135
- for (const raw of String(text || "").split(/\r?\n/)) {
136
- const m = raw.trim().match(/^(\S+)\s+v([\w.+-]+?)(\/go\.mod)?\s+h1:/);
137
- if (m && !m[3]) out.push({ ecosystem: "Go", name: m[1], version: m[2], dev: false, integrity: "", source: "go-sum" });
138
- }
139
- return dedupe(out);
140
- }
141
-
142
- // go.mod require versions — the fallback when there is no go.sum (fresh checkout / `go mod download`
143
- // not run). Pseudo-versions (v0.0.0-<ts>-<commit>) won't match OSV cleanly, but exact tags do; go.sum
144
- // (when present) supersedes these via dedupe. Leading `v` stripped to match OSV's Go versions.
145
- export function parseGoModPackages(text) {
146
- return dedupe(parseGoMod(text).requires.map((r) => ({ ecosystem: "Go", name: r.path, version: String(r.version).replace(/^v/, ""), dev: !!r.indirect, integrity: "", source: "go-mod" })));
147
- }
148
-
149
- // Top-level node_modules walk (incl. @scopes): the ground truth of what is REALLY on disk.
150
- function walkNodeModules(repoPath, { readJsonFile = readJson, readdir = readdirSync } = {}) {
151
- const out = [];
152
- const nm = join(repoPath, "node_modules");
153
- const readPkg = (dir, name) => {
154
- const pj = readJsonFile(join(dir, "package.json"));
155
- if (pj && pj.version) out.push({ ecosystem: "npm", name: pj.name || name, version: pj.version, dev: false, integrity: "", source: "node_modules" });
156
- };
157
- let entries;
158
- try { entries = readdir(nm); } catch { return out; }
159
- for (const e of entries) {
160
- if (e.startsWith(".")) continue;
161
- if (e.startsWith("@")) {
162
- let scoped; try { scoped = readdir(join(nm, e)); } catch { continue; }
163
- for (const s of scoped) readPkg(join(nm, e, s), `${e}/${s}`);
164
- } else readPkg(join(nm, e), e);
165
- }
166
- return out;
167
- }
168
-
169
- const readText = (p) => { try { return readFileSync(p, "utf8"); } catch { return null; } };
170
- const readJson = (p) => { try { return JSON.parse(readFileSync(p, "utf8")); } catch { return null; } };
171
-
172
- const SUBPROJECT_SKIP = new Set([".git", ".idea", ".vscode", ".venv", "venv", "env", "node_modules", "vendor", "dist", "build", "coverage", "__pycache__", ".tox", "testdata"]);
173
-
174
- function projectDirs(boundary) {
175
- const dirs = boundary.root ? [boundary.root] : [];
176
- let entries = [];
177
- try { entries = readdirSync(boundary.root, { withFileTypes: true }); } catch { return dirs; }
178
- for (const e of entries) {
179
- if (!e.isDirectory() || e.name.startsWith(".") || SUBPROJECT_SKIP.has(e.name)) continue;
180
- const resolved = boundary.resolve(e.name);
181
- if (resolved.ok) dirs.push(resolved.path);
182
- if (dirs.length >= 101) break;
183
- }
184
- return dirs;
185
- }
186
-
187
- function collectReqFiles(dir, readdir = readdirSync) {
188
- const reqFiles = [];
189
- try { for (const n of readdir(dir)) if (/^requirements[\w.-]*\.(txt|in)$/i.test(n)) reqFiles.push(join(dir, n)); } catch { /* unreadable root */ }
190
- try { for (const n of readdir(join(dir, "requirements"))) if (/\.(txt|in)$/i.test(n)) reqFiles.push(join(dir, "requirements", n)); } catch { /* no requirements/ dir */ }
191
- return reqFiles;
192
- }
193
-
194
- // → { installed: [{ecosystem,name,version,dev,source}], drift: [{name, locked, installed}] }
195
- export function collectInstalled(repoPath) {
196
- const boundary = createRepoBoundary(repoPath);
197
- if (!boundary.root) return { installed: [], drift: [] };
198
- const inside = (path) => boundary.resolve(relative(boundary.root, path) || ".");
199
- const boundedText = (path) => { const resolved = inside(path); return resolved.ok ? readText(resolved.path) : null; };
200
- const boundedJson = (path) => { const resolved = inside(path); return resolved.ok ? readJson(resolved.path) : null; };
201
- const boundedReaddir = (path, options) => {
202
- const resolved = inside(path);
203
- if (!resolved.ok) throw new Error("path is outside the repository");
204
- return readdirSync(resolved.path, options);
205
- };
206
- const dirs = projectDirs(boundary);
207
- const lock = [];
208
- const yarn = [];
209
- const disk = [];
210
- for (const dir of dirs) {
211
- const lockHere = parsePackageLock(boundedJson(join(dir, "package-lock.json")) || {});
212
- lock.push(...lockHere);
213
- if (!lockHere.length) yarn.push(...parseYarnLock(boundedText(join(dir, "yarn.lock")) || ""));
214
- disk.push(...walkNodeModules(dir, { readJsonFile: boundedJson, readdir: boundedReaddir }));
215
- }
216
- // Python: venv site-packages = the ground truth (exact installed versions); requirements*.txt (root +
217
- // a requirements/ dir) and poetry/uv/Pipfile locks fill in when there's no venv. venv wins per name.
218
- const venvPy = dirs.flatMap((dir) => collectVenvPackages(dir, { readdir: boundedReaddir }));
219
- const reqFiles = dirs.flatMap((dir) => collectReqFiles(dir, boundedReaddir));
220
- const venvNames = new Set(venvPy.map((p) => p.name));
221
- const pyDeclared = [
222
- ...reqFiles.flatMap((f) => parseRequirements(boundedText(f) || "")),
223
- ...dirs.flatMap((dir) => parseTomlLockPackages(boundedText(join(dir, "poetry.lock")) || "", "poetry-lock")),
224
- ...dirs.flatMap((dir) => parseTomlLockPackages(boundedText(join(dir, "uv.lock")) || "", "uv-lock")),
225
- ...dirs.flatMap((dir) => parsePipfileLock(boundedJson(join(dir, "Pipfile.lock")) || null)),
226
- ].filter((p) => !venvNames.has(p.name)); // installed version supersedes the declared pin
227
- const py = [...venvPy, ...pyDeclared];
228
- // Go: go.sum (exact, hashed) first, then go.mod require versions as a fallback. Walk the repo root
229
- // AND its immediate subdirectories so a Go MONOREPO (per-folder modules, no root go.mod — e.g. gpro)
230
- // still scans; dedupe() collapses the go.sum/go.mod overlap and cross-module shared deps.
231
- const goFromDir = (dir) => [...parseGoSum(boundedText(join(dir, "go.sum")) || ""), ...parseGoModPackages(boundedText(join(dir, "go.mod")) || "")];
232
- const go = [...goFromDir(boundary.root)];
233
- if (!go.length || boundary.resolve("go.work").ok) {
234
- let subs = [];
235
- try { subs = boundedReaddir(boundary.root, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && !["node_modules", "vendor", "dist", "build", "testdata"].includes(e.name)); } catch { /* unreadable root */ }
236
- for (const s of subs.slice(0, 100)) {
237
- const resolved = boundary.resolve(s.name);
238
- if (resolved.ok) go.push(...goFromDir(resolved.path));
239
- }
240
- }
241
-
242
- // lockfile wins as the version source; disk fills gaps + powers the drift signal. A package
243
- // legitimately appears at SEVERAL versions in a lockfile (yarn/npm nest transitive duplicates), so
244
- // track the FULL SET of locked versions per name. "Drift" = the installed version matches NONE of
245
- // them — the old code compared against ONE arbitrarily-picked entry, which faked drift (a top-level
246
- // @babel/code-frame@7.29.7 flagged against a nested 8.0.0 that is ALSO legitimately locked+installed).
247
- const locked = new Map(); // name -> representative entry (hoisted/lowest-depth) = the version source
248
- const lockedVers = new Map(); // name -> Set(every locked version)
249
- for (const p of [...yarn, ...lock]) {
250
- const prev = locked.get(p.name);
251
- if (!prev || (p.depth || 1) < (prev.depth || 1)) locked.set(p.name, p); // strictly-lower depth = hoisted
252
- (lockedVers.get(p.name) || lockedVers.set(p.name, new Set()).get(p.name)).add(p.version);
253
- }
254
- const merged = [...locked.values()];
255
- const drift = [];
256
- for (const d of disk) {
257
- const vers = lockedVers.get(d.name);
258
- if (!vers) merged.push(d);
259
- else if (!vers.has(d.version)) drift.push({ name: d.name, locked: locked.get(d.name).version, installed: d.version });
260
- }
261
- const jvmRust = collectJvmRustInstalled(repoPath);
262
- // The earlier fast path covers roots and immediate services. Complete the tracked repository
263
- // universe so deeply nested Python/Go services are not silently omitted from advisory coverage.
264
- const repositoryFiles = listRepoFiles(repoPath);
265
- const allPython = repositoryFiles.flatMap((file) => {
266
- const text = readRepoText(boundary, file);
267
- if (/(^|\/)requirements[\w.-]*\.(?:txt|in)$/i.test(file) || /(^|\/)requirements\/[^/]+\.(?:txt|in)$/i.test(file)) return parseRequirements(text || "");
268
- if (/(^|\/)poetry\.lock$/i.test(file)) return parseTomlLockPackages(text || "", "poetry-lock");
269
- if (/(^|\/)uv\.lock$/i.test(file)) return parseTomlLockPackages(text || "", "uv-lock");
270
- if (/(^|\/)Pipfile\.lock$/i.test(file)) { try { return parsePipfileLock(JSON.parse(text)); } catch { return []; } }
271
- return [];
272
- });
273
- const allGo = repositoryFiles.flatMap((file) => {
274
- const text = readRepoText(boundary, file) || "";
275
- if (/(^|\/)go\.sum$/i.test(file)) return parseGoSum(text);
276
- if (/(^|\/)go\.mod$/i.test(file)) return parseGoModPackages(text);
277
- return [];
278
- });
279
- return { installed: dedupe([...merged, ...py, ...go, ...allPython, ...allGo, ...jvmRust]), drift };
280
- }
@@ -1,121 +0,0 @@
1
- import { readFileSync, readdirSync, existsSync, statSync, openSync, readSync, closeSync } from "node:fs";
2
- import { join, relative } from "node:path";
3
- import { MALWARE_ALLOWLIST, classifyPythonPth } from "./registry-sig.js";
4
-
5
- const normPath = (p) => String(p || "").replace(/\\/g, "/").replace(/\/+$/, "");
6
- const existingDir = (p) => {
7
- try { return p && existsSync(p) && statSync(p).isDirectory(); } catch { return false; }
8
- };
9
-
10
- const PY_PTH_RE = /\.pth$/i;
11
- const BINARY_CANDIDATE_RE = /\.(exe|dll|dylib|so|node|bin)$/i;
12
- const BINARY_SUSPICIOUS_NAME_RE = /(^|[\\/])(postinstall|install|setup|update|loader|payload|helper|agent|service|runner)(\.[^\\/]+)?$/i;
13
- const NATIVE_SCRIPT_RE = /\b(node-gyp|node-pre-gyp|prebuild|node-gyp-build|cmake-js|cmake|make|napi|neon|cargo|go\s+build)\b/i;
14
- const NATIVE_DEP_RE = /^(node-addon-api|bindings|nan|prebuild-install|node-gyp|node-gyp-build|node-pre-gyp|@mapbox\/node-pre-gyp|cmake-js)$/i;
15
- const KNOWN_BINARY_PKG_RE = /^(?:@esbuild\/|@swc\/|@rollup\/rollup-|@img\/|@parcel\/watcher|esbuild$|sharp$|electron$|playwright$|@playwright\/|puppeteer$|cypress$|sass-embedded$|lightningcss$|tree-sitter$|tree-sitter-wasms$|better-sqlite3$|sqlite3$|bcrypt$|fsevents$|re2$|canvas$|workerd$)/i;
16
- const BUNDLED_BINARY_RULE = {
17
- key: "bundled-binary",
18
- severity: "medium",
19
- nearZeroFp: false,
20
- noisy: true,
21
- what: "bundled executable/native binary without native-build package metadata",
22
- };
23
-
24
- function readJsonFile(file) {
25
- try { return JSON.parse(readFileSync(file, "utf8")); } catch { return null; }
26
- }
27
-
28
- function hasNativeBuildHint(dir, pkgJson) {
29
- const pj = pkgJson || {};
30
- if (pj.gypfile || pj.binary || pj.os || pj.cpu) return true;
31
- if (existingDir(join(dir, "prebuilds")) || existsSync(join(dir, "binding.gyp"))) return true;
32
- const scriptText = Object.values(pj.scripts || {}).join("\n");
33
- if (NATIVE_SCRIPT_RE.test(scriptText)) return true;
34
- const deps = { ...(pj.dependencies || {}), ...(pj.optionalDependencies || {}), ...(pj.devDependencies || {}) };
35
- return Object.keys(deps).some((name) => NATIVE_DEP_RE.test(name));
36
- }
37
-
38
- function binaryMagic(file) {
39
- let fd = null;
40
- try {
41
- fd = openSync(file, "r");
42
- const b = Buffer.alloc(8);
43
- const n = readSync(fd, b, 0, b.length, 0);
44
- if (n >= 2 && b[0] === 0x4d && b[1] === 0x5a) return "PE";
45
- if (n >= 4 && b[0] === 0x7f && b[1] === 0x45 && b[2] === 0x4c && b[3] === 0x46) return "ELF";
46
- if (n >= 4) {
47
- const hex = b.subarray(0, 4).toString("hex");
48
- if (["feedface", "feedfacf", "cefaedfe", "cffaedfe", "cafebabe", "cafebabf"].includes(hex)) return "Mach-O";
49
- }
50
- } catch { /* not readable */ }
51
- finally { if (fd != null) { try { closeSync(fd); } catch { /* ignore */ } } }
52
- return "";
53
- }
54
-
55
- function shouldSkipMetaPath(rel) {
56
- const p = normPath(rel).toLowerCase();
57
- return /(^|\/)(node_modules|\.git|docs?|documentation|test|tests|__tests__|fixtures?|examples?|coverage|dist-types)(\/|$)/.test(p) || /\.(map|md|mdx|markdown|rst|txt|d\.ts)$/i.test(p);
58
- }
59
-
60
- function binaryArtifactSweep(pkgDirs, capFiles = 12000) {
61
- const hits = [];
62
- let seen = 0;
63
- for (const { pkg, dir } of pkgDirs) {
64
- if (seen >= capFiles) break;
65
- if (MALWARE_ALLOWLIST.has(pkg) || KNOWN_BINARY_PKG_RE.test(pkg)) continue;
66
- const pj = readJsonFile(join(dir, "package.json")) || {};
67
- if (hasNativeBuildHint(dir, pj)) continue;
68
- const stack = [dir];
69
- while (stack.length && seen < capFiles) {
70
- const cur = stack.pop();
71
- let entries = [];
72
- try { entries = readdirSync(cur, { withFileTypes: true }); } catch { continue; }
73
- for (const e of entries) {
74
- const full = join(cur, e.name);
75
- const rel = relative(dir, full);
76
- if (shouldSkipMetaPath(rel)) continue;
77
- if (e.isDirectory()) { stack.push(full); continue; }
78
- if (!e.isFile()) continue;
79
- seen++;
80
- if (!BINARY_CANDIDATE_RE.test(e.name) && !BINARY_SUSPICIOUS_NAME_RE.test(full)) continue;
81
- let st; try { st = statSync(full); } catch { continue; }
82
- if (!st.size || st.size > 80_000_000) continue;
83
- const kind = binaryMagic(full);
84
- if (!kind) continue;
85
- hits.push({
86
- pkg,
87
- file: full,
88
- line: 0,
89
- text: `${kind} binary ${normPath(rel)} in package with no native-build metadata`,
90
- rule: BUNDLED_BINARY_RULE,
91
- });
92
- break;
93
- }
94
- }
95
- }
96
- return hits;
97
- }
98
-
99
- function pythonPthSweep(contentRoots) {
100
- const hits = [];
101
- for (const root of contentRoots) {
102
- if (root.kind !== "PyPI") continue;
103
- let entries = [];
104
- try { entries = readdirSync(root.root, { withFileTypes: true }); } catch { continue; }
105
- for (const e of entries) {
106
- if (!e.isFile() || !PY_PTH_RE.test(e.name)) continue;
107
- const file = join(root.root, e.name);
108
- let text = "";
109
- try { text = readFileSync(file, "utf8"); } catch { continue; }
110
- const pkg = root.pathToPkg(file) || e.name.replace(PY_PTH_RE, "");
111
- for (const sig of classifyPythonPth(text)) {
112
- hits.push({ pkg, file, line: sig.line || 0, text: sig.snippet || "", rule: sig });
113
- }
114
- }
115
- }
116
- return hits;
117
- }
118
-
119
- export function fileHeuristicSweep(contentRoots, pkgDirs) {
120
- return [...pythonPthSweep(contentRoots), ...binaryArtifactSweep(pkgDirs)];
121
- }
@@ -1,134 +0,0 @@
1
- // Allowlist/exclusion parsing and URL/doc-noise filters for the malware scanner (split out of
2
- // malware-heuristics.js; see that file for the scanner overview).
3
- import { NOISY_URL_KEYS, isDocFile, isBenignUrlContext } from "./registry-sig.js";
4
-
5
- export const normPath = (p) => String(p || "").replace(/\\/g, "/").replace(/\/+$/, "");
6
- const URL_RULE_KEYS = new Set(["exfil-url", "exfil-ip", "cloud-metadata-url", "network-url", "hardcoded-url"]);
7
- const URL_RE = /https?:\/\/[^\s'"`)\\<>]+/gi;
8
- const PACKAGE_JSON_SCRIPT_RE = /["']?(preinstall|install|postinstall|prepare|prepack|postpack|prepublish|prepublishonly)["']?\s*:/i;
9
- const PACKAGE_JSON_METADATA_URL_RE = /["']?(bugs|homepage|repository|funding|author|contributors|maintainers|publishConfig|license)["']?\s*:|["']?url["']?\s*:/i;
10
- const NETWORK_CALL_RE = /\b(fetch|axios\.|XMLHttpRequest|sendBeacon|https?\.request|request\(|curl\b|wget\b|iwr\b|invoke-webrequest)\b/i;
11
- const INSTALL_SCRIPT_HOOKS = ["preinstall", "install", "postinstall"];
12
-
13
- function cleanUrlToken(value) {
14
- return String(value || "").trim().replace(/[.,;:!?]+$/g, "").replace(/[)\]}]+$/g, "");
15
- }
16
-
17
- function splitAllowlistText(value) {
18
- if (Array.isArray(value)) return value.flatMap(splitAllowlistText);
19
- return String(value || "")
20
- .split(/[\r\n,]+/)
21
- .map((line) => line.replace(/\s+#.*$/, "").trim())
22
- .filter(Boolean);
23
- }
24
-
25
- function normalizeHost(value) {
26
- let s = String(value || "").trim().toLowerCase();
27
- if (!s) return "";
28
- try {
29
- if (/^https?:\/\//i.test(s)) s = new URL(s).host;
30
- } catch { /* keep raw */ }
31
- return s.replace(/^\*\./, "").replace(/^\./, "").replace(/:\d+$/, "");
32
- }
33
-
34
- function normalizeUrl(value) {
35
- const raw = cleanUrlToken(value);
36
- if (!raw) return "";
37
- try {
38
- const u = new URL(raw);
39
- const path = u.pathname.replace(/\/+$/, "");
40
- return `${u.protocol.toLowerCase()}//${u.host.toLowerCase()}${path}${u.search || ""}`;
41
- } catch {
42
- return raw.toLowerCase().replace(/\/+$/, "");
43
- }
44
- }
45
-
46
- function extractUrls(text) {
47
- return [...String(text || "").matchAll(URL_RE)].map((m) => cleanUrlToken(m[0])).filter(Boolean);
48
- }
49
-
50
- function urlMatchesAllow(allowUrl, candidate) {
51
- const a = normalizeUrl(allowUrl);
52
- const c = normalizeUrl(candidate);
53
- if (!a || !c) return false;
54
- return c === a || c.startsWith(`${a}/`) || a.startsWith(`${c}/`);
55
- }
56
-
57
- function hostMatchesAllow(allowHost, candidate) {
58
- const a = normalizeHost(allowHost);
59
- const c = normalizeHost(candidate);
60
- return !!(a && c && (c === a || c.endsWith(`.${a}`)));
61
- }
62
-
63
- export function parseMalwareExclusions(input = {}) {
64
- const out = { urls: [], hosts: [], packages: [], rules: [] };
65
- const add = (raw) => {
66
- const s = cleanUrlToken(raw);
67
- if (!s) return;
68
- const lower = s.toLowerCase();
69
- if (lower.startsWith("pkg:")) { out.packages.push(s.slice(4).trim()); return; }
70
- if (lower.startsWith("package:")) { out.packages.push(s.slice(8).trim()); return; }
71
- if (lower.startsWith("rule:")) { out.rules.push(s.slice(5).trim()); return; }
72
- if (lower.startsWith("host:")) { out.hosts.push(normalizeHost(s.slice(5))); return; }
73
- if (lower.startsWith("domain:")) { out.hosts.push(normalizeHost(s.slice(7))); return; }
74
- if (/^https?:\/\//i.test(s)) { out.urls.push(normalizeUrl(s)); out.hosts.push(normalizeHost(s)); return; }
75
- if (!s.includes("/") && s.includes(".")) { out.hosts.push(normalizeHost(s)); return; }
76
- out.packages.push(s);
77
- };
78
- if (typeof input === "string" || Array.isArray(input)) {
79
- for (const line of splitAllowlistText(input)) add(line);
80
- } else if (input && typeof input === "object") {
81
- for (const line of splitAllowlistText(input.urls || input.url || "")) add(line);
82
- for (const line of splitAllowlistText(input.domains || input.domain || "")) add(`host:${line}`);
83
- for (const line of splitAllowlistText(input.packages || input.package || "")) add(/^pkg(age)?:/i.test(line) ? line : `pkg:${line}`);
84
- for (const line of splitAllowlistText(input.rules || input.rule || "")) add(`rule:${line}`);
85
- }
86
- return {
87
- urls: [...new Set(out.urls.filter(Boolean))],
88
- hosts: [...new Set(out.hosts.filter(Boolean))],
89
- packages: [...new Set(out.packages.map((p) => p.trim()).filter(Boolean))],
90
- rules: [...new Set(out.rules.map((r) => r.trim()).filter(Boolean))],
91
- };
92
- }
93
-
94
- export function isManifestUrlNoise(file, signal) {
95
- if (!URL_RULE_KEYS.has(signal?.key)) return false;
96
- const f = normPath(file).toLowerCase();
97
- const text = `${signal?.snippet || ""}`.trim();
98
- if (/(^|\/)package\.json$/.test(f)) {
99
- if (PACKAGE_JSON_SCRIPT_RE.test(text)) return false;
100
- return PACKAGE_JSON_METADATA_URL_RE.test(text) || !NETWORK_CALL_RE.test(text);
101
- }
102
- return /(^|\/)(pkg-info|metadata)$/.test(f);
103
- }
104
-
105
- export function installScriptSnippet(scripts = {}) {
106
- for (const hook of INSTALL_SCRIPT_HOOKS) {
107
- const s = String(scripts?.[hook] || "").trim();
108
- if (s) return `${hook}: ${s}`.slice(0, 200);
109
- }
110
- return "";
111
- }
112
-
113
- // weak URL rules only: URL evidence in a license/prose file or in comment/doc-link context is
114
- // documentation, not behavior (a license-header scheme reference on LICENSE line 5 was the hot FP).
115
- // Strong rules (miner/shell/exfil-url) are untouched and still scan those same files.
116
- export function isDocUrlNoise(file, signal) {
117
- if (!NOISY_URL_KEYS.has(signal?.key)) return false;
118
- return isDocFile(file) || isBenignUrlContext(signal?.snippet || "");
119
- }
120
-
121
- export function isMalwareSignalExcluded(pkg, signal, exclusions = {}) {
122
- const ex = exclusions.urls || exclusions.hosts || exclusions.packages || exclusions.rules ? exclusions : parseMalwareExclusions(exclusions);
123
- if (signal?.key && ex.rules.includes(signal.key)) return true;
124
- if (ex.packages.some((p) => p.toLowerCase() === String(pkg || "").toLowerCase()) && signal?.noisy) return true;
125
- if (!URL_RULE_KEYS.has(signal?.key)) return false;
126
- const text = `${signal?.snippet || ""}\n${signal?.file || ""}`;
127
- const urls = extractUrls(text);
128
- for (const url of urls) {
129
- if (ex.urls.some((allowed) => urlMatchesAllow(allowed, url))) return true;
130
- if (ex.hosts.some((allowed) => hostMatchesAllow(allowed, url))) return true;
131
- }
132
- if (!urls.length && ex.hosts.some((host) => host && text.toLowerCase().includes(host))) return true;
133
- return false;
134
- }
@@ -1,15 +0,0 @@
1
- // Heuristic malware scanner over INSTALLED dependencies (defensive): install-script beacons, crypto-
2
- // miner signatures, exfiltration endpoints, obfuscation markers, non-registry install sources.
3
- // Phase A (always, cheap): every installed package's package.json scripts + lockfile `resolved` origin.
4
- // Phase B (content): ripgrep sweep of node_modules when rg is available (full coverage), else a bounded
5
- // Node fallback over each package's entry files. Multi-signal scoring per package: high/critical needs
6
- // a near-zero-FP rule OR >=2 independent rule keys; the allowlist downgrades ONLY noisy rules.
7
- // This catches known PATTERNS — it is not a sandbox or a reputation service (honest limit, in the UI).
8
- // Split into sibling modules (this file stays the import path):
9
- // malware-heuristics.exclusions.js - allowlist parsing + URL/doc noise filters
10
- // malware-heuristics.roots.js - content roots + path-to-package mapping
11
- // malware-heuristics.sweep.js - ripgrep / Node content sweeps
12
- // malware-heuristics.scan.js - scanMalware orchestration
13
- export { parseMalwareExclusions, isMalwareSignalExcluded } from "./malware-heuristics.exclusions.js";
14
- export { pkgOfNodeModulesPath } from "./malware-heuristics.roots.js";
15
- export { scanMalware } from "./malware-heuristics.scan.js";