weavatrix 0.3.14 → 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 (305) 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 -66
  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.14.md +0 -37
  28. package/docs/releases/v0.3.2.md +0 -15
  29. package/docs/releases/v0.3.3.md +0 -25
  30. package/docs/releases/v0.3.4.md +0 -40
  31. package/docs/releases/v0.3.5.md +0 -50
  32. package/docs/releases/v0.3.6.md +0 -44
  33. package/docs/releases/v0.3.7.md +0 -37
  34. package/docs/releases/v0.3.8.md +0 -21
  35. package/docs/releases/v0.3.9.md +0 -36
  36. package/scripts/run-agent-task-benchmark.mjs +0 -118
  37. package/src/analysis/allowed-test-runner.js +0 -70
  38. package/src/analysis/architecture/contract-graph.js +0 -119
  39. package/src/analysis/architecture/contract-schema.js +0 -110
  40. package/src/analysis/architecture/contract-storage.js +0 -35
  41. package/src/analysis/architecture/contract-verification.js +0 -168
  42. package/src/analysis/architecture-contract.js +0 -16
  43. package/src/analysis/audit-debt.js +0 -94
  44. package/src/analysis/audit-extensions.js +0 -60
  45. package/src/analysis/cargo-dependency-evidence.js +0 -108
  46. package/src/analysis/cargo-manifests.js +0 -81
  47. package/src/analysis/change-classification/diff-parser.js +0 -103
  48. package/src/analysis/change-classification/options.js +0 -40
  49. package/src/analysis/change-classification/symbol-classifier.js +0 -177
  50. package/src/analysis/change-classification.js +0 -188
  51. package/src/analysis/coverage-reports-tarpaulin.js +0 -112
  52. package/src/analysis/coverage-reports.js +0 -246
  53. package/src/analysis/cycle-route.js +0 -14
  54. package/src/analysis/data-flow-evidence.js +0 -114
  55. package/src/analysis/dead-check.js +0 -300
  56. package/src/analysis/dead-code-review/candidates.js +0 -194
  57. package/src/analysis/dead-code-review/policy.js +0 -23
  58. package/src/analysis/dead-code-review.js +0 -119
  59. package/src/analysis/dep-check-ecosystems.js +0 -205
  60. package/src/analysis/dep-check.js +0 -290
  61. package/src/analysis/dep-rules.js +0 -10
  62. package/src/analysis/dependency/conventions.js +0 -16
  63. package/src/analysis/dependency/scoped-dependencies.js +0 -51
  64. package/src/analysis/dependency/source-references.js +0 -21
  65. package/src/analysis/duplicate-groups.js +0 -104
  66. package/src/analysis/duplicates-worker.js +0 -11
  67. package/src/analysis/duplicates.compute.js +0 -269
  68. package/src/analysis/duplicates.js +0 -15
  69. package/src/analysis/duplicates.run.js +0 -52
  70. package/src/analysis/duplicates.tokenize.js +0 -199
  71. package/src/analysis/endpoints/common.js +0 -79
  72. package/src/analysis/endpoints/extract.js +0 -120
  73. package/src/analysis/endpoints/inventory.js +0 -84
  74. package/src/analysis/endpoints/mounts.js +0 -129
  75. package/src/analysis/endpoints-java.js +0 -260
  76. package/src/analysis/endpoints-rust.js +0 -124
  77. package/src/analysis/endpoints.js +0 -3
  78. package/src/analysis/findings.js +0 -70
  79. package/src/analysis/git-history/analytics.js +0 -177
  80. package/src/analysis/git-history/collector.js +0 -67
  81. package/src/analysis/git-history/options.js +0 -66
  82. package/src/analysis/git-history.js +0 -143
  83. package/src/analysis/git-ref-graph.js +0 -76
  84. package/src/analysis/go-dependency-evidence.js +0 -62
  85. package/src/analysis/graph-analysis.aggregate.js +0 -296
  86. package/src/analysis/graph-analysis.edges.js +0 -24
  87. package/src/analysis/graph-analysis.js +0 -7
  88. package/src/analysis/graph-analysis.refs.js +0 -202
  89. package/src/analysis/graph-analysis.summaries.js +0 -65
  90. package/src/analysis/health-capabilities.js +0 -83
  91. package/src/analysis/hot-path-review.js +0 -266
  92. package/src/analysis/http-contract-wrappers.js +0 -241
  93. package/src/analysis/http-contracts/analysis.js +0 -179
  94. package/src/analysis/http-contracts/client-call-detection.js +0 -82
  95. package/src/analysis/http-contracts/client-call-parser.js +0 -273
  96. package/src/analysis/http-contracts/graph-context.js +0 -143
  97. package/src/analysis/http-contracts/matching.js +0 -61
  98. package/src/analysis/http-contracts/shared.js +0 -85
  99. package/src/analysis/http-contracts.js +0 -6
  100. package/src/analysis/internal-audit/dependency-health.js +0 -113
  101. package/src/analysis/internal-audit/python-manifests.js +0 -78
  102. package/src/analysis/internal-audit/repo-files.js +0 -50
  103. package/src/analysis/internal-audit/supply-chain.js +0 -149
  104. package/src/analysis/internal-audit.collect.js +0 -213
  105. package/src/analysis/internal-audit.js +0 -9
  106. package/src/analysis/internal-audit.reach.js +0 -201
  107. package/src/analysis/internal-audit.run.js +0 -256
  108. package/src/analysis/java-source.js +0 -36
  109. package/src/analysis/jvm-artifact-index.js +0 -87
  110. package/src/analysis/jvm-dependency-evidence.js +0 -138
  111. package/src/analysis/jvm-manifests.js +0 -114
  112. package/src/analysis/manifests.js +0 -123
  113. package/src/analysis/package-reachability.js +0 -39
  114. package/src/analysis/source-complexity.ast.js +0 -97
  115. package/src/analysis/source-complexity.constants.js +0 -55
  116. package/src/analysis/source-complexity.js +0 -14
  117. package/src/analysis/source-complexity.report.js +0 -81
  118. package/src/analysis/source-complexity.walk.js +0 -228
  119. package/src/analysis/source-correctness/retry-patterns.js +0 -93
  120. package/src/analysis/source-correctness.js +0 -222
  121. package/src/analysis/static-test-reachability.js +0 -150
  122. package/src/analysis/structure/dependency-graph.js +0 -151
  123. package/src/analysis/structure/findings.js +0 -162
  124. package/src/analysis/task-retrieval.js +0 -107
  125. package/src/analysis/transport-contracts.js +0 -224
  126. package/src/analysis/transport-runtime-evidence.js +0 -155
  127. package/src/analysis-kit.mjs +0 -17
  128. package/src/bounds.js +0 -4
  129. package/src/build-graph.js +0 -209
  130. package/src/child-env.js +0 -7
  131. package/src/config.js +0 -5
  132. package/src/extension/local-services.mjs +0 -75
  133. package/src/git-exec.js +0 -67
  134. package/src/graph/build-worker.js +0 -49
  135. package/src/graph/builder/go-receiver-resolution.js +0 -112
  136. package/src/graph/builder/js/dynamic-import.js +0 -26
  137. package/src/graph/builder/js/queries.js +0 -48
  138. package/src/graph/builder/lang-csharp.js +0 -40
  139. package/src/graph/builder/lang-css.js +0 -29
  140. package/src/graph/builder/lang-go.js +0 -140
  141. package/src/graph/builder/lang-html.js +0 -29
  142. package/src/graph/builder/lang-java-calls.js +0 -142
  143. package/src/graph/builder/lang-java.js +0 -215
  144. package/src/graph/builder/lang-js.js +0 -291
  145. package/src/graph/builder/lang-python.js +0 -235
  146. package/src/graph/builder/lang-rust-calls.js +0 -63
  147. package/src/graph/builder/lang-rust.js +0 -299
  148. package/src/graph/builder/lang-solidity.js +0 -126
  149. package/src/graph/builder/lang-sql.js +0 -263
  150. package/src/graph/builder/pass2-resolution.js +0 -81
  151. package/src/graph/builder/spec-pkg.js +0 -87
  152. package/src/graph/community.js +0 -27
  153. package/src/graph/edge-provenance.js +0 -31
  154. package/src/graph/file-lock.js +0 -69
  155. package/src/graph/freshness-probe.js +0 -142
  156. package/src/graph/graph-filter.js +0 -63
  157. package/src/graph/incremental-refresh.js +0 -235
  158. package/src/graph/internal-builder.barrels.js +0 -235
  159. package/src/graph/internal-builder.build.js +0 -300
  160. package/src/graph/internal-builder.java.js +0 -33
  161. package/src/graph/internal-builder.js +0 -12
  162. package/src/graph/internal-builder.langs.js +0 -157
  163. package/src/graph/internal-builder.pass2.js +0 -163
  164. package/src/graph/internal-builder.resolvers.js +0 -286
  165. package/src/graph/layout.js +0 -51
  166. package/src/graph/node-id.js +0 -7
  167. package/src/graph/parser-artifact-boundary.js +0 -55
  168. package/src/graph/relations.js +0 -4
  169. package/src/graph/repo-registry.js +0 -124
  170. package/src/graph/resolvers/rust.js +0 -117
  171. package/src/infra/infra-items.js +0 -255
  172. package/src/infra/infra-registry.js +0 -184
  173. package/src/infra/infra.detect.js +0 -119
  174. package/src/infra/infra.js +0 -38
  175. package/src/infra/infra.match.js +0 -102
  176. package/src/infra/infra.scan.js +0 -93
  177. package/src/mcp/actions/graph-lifecycle.mjs +0 -148
  178. package/src/mcp/architecture-bootstrap.mjs +0 -168
  179. package/src/mcp/architecture-starter.mjs +0 -234
  180. package/src/mcp/catalog.mjs +0 -233
  181. package/src/mcp/company-contract-page.mjs +0 -142
  182. package/src/mcp/company-contract-reconcile.mjs +0 -87
  183. package/src/mcp/company-contract-verdict.mjs +0 -42
  184. package/src/mcp/evidence/bun-lock-graph.mjs +0 -209
  185. package/src/mcp/evidence/duplicate-member-order.mjs +0 -8
  186. package/src/mcp/evidence/package-graph-common.mjs +0 -115
  187. package/src/mcp/evidence/package-lock-graph.mjs +0 -92
  188. package/src/mcp/evidence-snapshot.architecture.mjs +0 -80
  189. package/src/mcp/evidence-snapshot.common.mjs +0 -158
  190. package/src/mcp/evidence-snapshot.duplicates.mjs +0 -213
  191. package/src/mcp/evidence-snapshot.health.mjs +0 -102
  192. package/src/mcp/evidence-snapshot.inventory.mjs +0 -148
  193. package/src/mcp/evidence-snapshot.mjs +0 -50
  194. package/src/mcp/evidence-snapshot.package-graph.mjs +0 -34
  195. package/src/mcp/evidence-snapshot.structure.mjs +0 -84
  196. package/src/mcp/extension-api.mjs +0 -77
  197. package/src/mcp/git-output.mjs +0 -7
  198. package/src/mcp/graph/context-core.mjs +0 -111
  199. package/src/mcp/graph/context-seeds.mjs +0 -207
  200. package/src/mcp/graph/context-state.mjs +0 -85
  201. package/src/mcp/graph/reverse-reach.mjs +0 -42
  202. package/src/mcp/graph/tools-core.mjs +0 -143
  203. package/src/mcp/graph/tools-query.mjs +0 -276
  204. package/src/mcp/graph-context.mjs +0 -5
  205. package/src/mcp/graph-diff.mjs +0 -218
  206. package/src/mcp/health/audit-format.mjs +0 -199
  207. package/src/mcp/health/audit.mjs +0 -199
  208. package/src/mcp/health/dead-code.mjs +0 -110
  209. package/src/mcp/health/duplicates.mjs +0 -121
  210. package/src/mcp/health/endpoints.mjs +0 -71
  211. package/src/mcp/health/structure.mjs +0 -220
  212. package/src/mcp/runtime-version.mjs +0 -31
  213. package/src/mcp/server/auto-refresh.mjs +0 -66
  214. package/src/mcp/server/runtime-config.mjs +0 -43
  215. package/src/mcp/server/shutdown.mjs +0 -40
  216. package/src/mcp/staleness-notice.mjs +0 -20
  217. package/src/mcp/sync/evidence-architecture.mjs +0 -54
  218. package/src/mcp/sync/evidence-common.mjs +0 -88
  219. package/src/mcp/sync/evidence-duplicates.mjs +0 -97
  220. package/src/mcp/sync/evidence-health.mjs +0 -56
  221. package/src/mcp/sync/evidence-packages.mjs +0 -95
  222. package/src/mcp/sync/payload-common.mjs +0 -97
  223. package/src/mcp/sync/payload-v2.mjs +0 -54
  224. package/src/mcp/sync/payload-v3.mjs +0 -79
  225. package/src/mcp/sync-evidence.mjs +0 -23
  226. package/src/mcp/sync-payload.mjs +0 -70
  227. package/src/mcp/tool-result.mjs +0 -54
  228. package/src/mcp/tools-actions.mjs +0 -11
  229. package/src/mcp/tools-architecture.mjs +0 -177
  230. package/src/mcp/tools-company.mjs +0 -251
  231. package/src/mcp/tools-context.mjs +0 -222
  232. package/src/mcp/tools-endpoints.mjs +0 -207
  233. package/src/mcp/tools-graph-hubs.mjs +0 -78
  234. package/src/mcp/tools-graph.mjs +0 -17
  235. package/src/mcp/tools-health.mjs +0 -24
  236. package/src/mcp/tools-history.mjs +0 -28
  237. package/src/mcp/tools-impact-change.mjs +0 -220
  238. package/src/mcp/tools-impact-precision.mjs +0 -89
  239. package/src/mcp/tools-impact.mjs +0 -169
  240. package/src/mcp/tools-source.mjs +0 -238
  241. package/src/mcp/tools-verified-change.mjs +0 -200
  242. package/src/mcp-rg.mjs +0 -50
  243. package/src/mcp-runtime.mjs +0 -2
  244. package/src/mcp-server.mjs +0 -298
  245. package/src/mcp-source-tools.mjs +0 -163
  246. package/src/path-classification.js +0 -226
  247. package/src/path-ignore.js +0 -69
  248. package/src/precision/lsp-client/constants.js +0 -12
  249. package/src/precision/lsp-client/environment.js +0 -20
  250. package/src/precision/lsp-client/errors.js +0 -15
  251. package/src/precision/lsp-client/lifecycle.js +0 -114
  252. package/src/precision/lsp-client/message-parser.js +0 -81
  253. package/src/precision/lsp-client/protocol.js +0 -212
  254. package/src/precision/lsp-client/registry.js +0 -59
  255. package/src/precision/lsp-client/repo-uri.js +0 -60
  256. package/src/precision/lsp-client/stdio-client.js +0 -140
  257. package/src/precision/lsp-client.js +0 -10
  258. package/src/precision/lsp-overlay/budget-policy.js +0 -78
  259. package/src/precision/lsp-overlay/build.js +0 -261
  260. package/src/precision/lsp-overlay/contract.js +0 -61
  261. package/src/precision/lsp-overlay/reference-results.js +0 -108
  262. package/src/precision/lsp-overlay/semantic-inputs.js +0 -62
  263. package/src/precision/lsp-overlay/source-session.js +0 -142
  264. package/src/precision/lsp-overlay/store.js +0 -150
  265. package/src/precision/lsp-overlay/target-index.js +0 -152
  266. package/src/precision/lsp-overlay/target-query.js +0 -55
  267. package/src/precision/lsp-overlay.js +0 -11
  268. package/src/precision/symbol-query.js +0 -224
  269. package/src/precision/typescript-lsp-provider.js +0 -12
  270. package/src/precision/typescript-provider/client.js +0 -89
  271. package/src/precision/typescript-provider/discovery.js +0 -124
  272. package/src/precision/typescript-provider/isolated-runtime.js +0 -39
  273. package/src/precision/typescript-provider/project-host.js +0 -254
  274. package/src/precision/typescript-provider/project-safety.js +0 -166
  275. package/src/precision/typescript-provider/reference-usage.js +0 -53
  276. package/src/process.js +0 -95
  277. package/src/repo-path.js +0 -53
  278. package/src/scan/discover.inventory.js +0 -78
  279. package/src/scan/discover.js +0 -5
  280. package/src/scan/discover.list.js +0 -79
  281. package/src/scan/discover.stack.js +0 -227
  282. package/src/scan/search.core.js +0 -24
  283. package/src/scan/search.git.js +0 -102
  284. package/src/scan/search.js +0 -9
  285. package/src/scan/search.node.js +0 -83
  286. package/src/scan/search.preview.js +0 -49
  287. package/src/scan/search.rg.js +0 -145
  288. package/src/security/advisory-store.js +0 -172
  289. package/src/security/installed-jvm-rust.js +0 -46
  290. package/src/security/installed.js +0 -280
  291. package/src/security/malware-file-heuristics.js +0 -121
  292. package/src/security/malware-heuristics.exclusions.js +0 -134
  293. package/src/security/malware-heuristics.js +0 -15
  294. package/src/security/malware-heuristics.roots.js +0 -145
  295. package/src/security/malware-heuristics.scan.js +0 -89
  296. package/src/security/malware-heuristics.sweep.js +0 -122
  297. package/src/security/malware-scoring.js +0 -105
  298. package/src/security/match.js +0 -85
  299. package/src/security/registry-sig.classify.js +0 -137
  300. package/src/security/registry-sig.js +0 -18
  301. package/src/security/registry-sig.rules.js +0 -192
  302. package/src/security/rust-advisory-report.js +0 -60
  303. package/src/security/typosquat.js +0 -81
  304. package/src/util.js +0 -40
  305. 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";