@clear-capabilities/agentic-security-scanner 0.185.0 → 0.186.2

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 (174) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/bin/agentic-security.js +66 -18
  3. package/dist/1128.index.js +25 -21
  4. package/dist/{5817.index.js → 1602.index.js} +378 -29
  5. package/dist/2584.index.js +1 -1
  6. package/dist/4171.index.js +2 -2
  7. package/dist/{0b301d45b231f144a1b4.json → 4d06c8944ae121d7085c.json} +8 -8
  8. package/dist/5752.index.js +466 -0
  9. package/dist/7405.index.js +1 -1
  10. package/dist/8158.index.js +1713 -0
  11. package/dist/8798.index.js +1 -1
  12. package/dist/9382.index.js +2 -2
  13. package/dist/9560.index.js +1 -1
  14. package/dist/9579.index.js +1 -1
  15. package/dist/agentic-security.mjs +29 -29
  16. package/dist/agentic-security.mjs.sha256 +1 -1
  17. package/package.json +8 -8
  18. package/src/dataflow/CLAUDE.md +6 -3
  19. package/src/dataflow/access-paths.js +12 -2
  20. package/src/dataflow/demand-query.js +279 -40
  21. package/src/dataflow/dep-fingerprint.js +1 -1
  22. package/src/dataflow/exploit-prover.js +6 -2
  23. package/src/dataflow/ir-cache.js +268 -0
  24. package/src/dataflow/privacy-taint.js +7 -0
  25. package/src/engine.js +62 -5
  26. package/src/ir/CLAUDE.md +4 -0
  27. package/src/ir/callgraph.js +36 -8
  28. package/src/ir/index.js +18 -4
  29. package/src/ir/parser-js.js +10 -0
  30. package/src/language/CLAUDE.md +13 -0
  31. package/src/language/nix-option-types.js +170 -0
  32. package/src/language/nix-script-taint.js +46 -3
  33. package/src/language/nix-secrets.js +20 -2
  34. package/src/lineage/CLAUDE.md +2 -1
  35. package/src/lineage/smt-orchestrator.js +47 -11
  36. package/src/lineage/smt-z3-backend.js +294 -0
  37. package/src/posture/CLAUDE.md +5 -1
  38. package/src/posture/business-logic.js +16 -7
  39. package/src/posture/dag-commands.js +442 -0
  40. package/src/posture/finding-defaults.js +19 -0
  41. package/src/posture/git-history.js +91 -1
  42. package/src/posture/proof-fabric/cli.js +1 -1
  43. package/src/posture/proof-fabric/container.js +2 -2
  44. package/src/posture/proof-fabric/generate-haskell.js +205 -0
  45. package/src/posture/proof-fabric/generate.js +6 -3
  46. package/src/posture/proof-fabric/reproducer.js +4 -2
  47. package/src/posture/proof-fabric/runner.js +4 -4
  48. package/src/sast/CLAUDE.md +2 -0
  49. package/src/sast/_call-args.js +70 -0
  50. package/src/sast/init-scope.js +87 -0
  51. package/src/sast/listen-bind-address.js +49 -0
  52. package/src/sast/redirect-target.js +106 -0
  53. package/src/sast/reflected-input.js +76 -0
  54. package/src/sast/send-file-root.js +27 -0
  55. package/src/sast/sensitive-data-logging.js +38 -1
  56. package/dist/119.index.js +0 -197
  57. package/dist/128.index.js +0 -129
  58. package/dist/1293.index.js +0 -5689
  59. package/dist/1336.index.js +0 -16331
  60. package/dist/1351.index.js +0 -133
  61. package/dist/1387.index.js +0 -271
  62. package/dist/1437.index.js +0 -23
  63. package/dist/1445.index.js +0 -110
  64. package/dist/1505.index.js +0 -151
  65. package/dist/1557.index.js +0 -293
  66. package/dist/1621.index.js +0 -311
  67. package/dist/1751.index.js +0 -160
  68. package/dist/1765.index.js +0 -727
  69. package/dist/1861.index.js +0 -690
  70. package/dist/1906.index.js +0 -433
  71. package/dist/208.index.js +0 -1631
  72. package/dist/2223.index.js +0 -159
  73. package/dist/2238.index.js +0 -295
  74. package/dist/2530.index.js +0 -152
  75. package/dist/2565.index.js +0 -116
  76. package/dist/2574.index.js +0 -127
  77. package/dist/2620.index.js +0 -345
  78. package/dist/2773.index.js +0 -98
  79. package/dist/2775.index.js +0 -32
  80. package/dist/2966.index.js +0 -171
  81. package/dist/2972.index.js +0 -87
  82. package/dist/2991.index.js +0 -131
  83. package/dist/3063.index.js +0 -833
  84. package/dist/3075.index.js +0 -227
  85. package/dist/3121.index.js +0 -297
  86. package/dist/3314.index.js +0 -263
  87. package/dist/3480.index.js +0 -1822
  88. package/dist/3481.index.js +0 -24
  89. package/dist/3506.index.js +0 -268
  90. package/dist/3533.index.js +0 -591
  91. package/dist/3653.index.js +0 -450
  92. package/dist/3740.index.js +0 -722
  93. package/dist/3822.index.js +0 -131
  94. package/dist/3868.index.js +0 -292
  95. package/dist/3918.index.js +0 -192
  96. package/dist/4090.index.js +0 -288
  97. package/dist/4113.index.js +0 -1286
  98. package/dist/4121.index.js +0 -1190
  99. package/dist/4142.index.js +0 -690
  100. package/dist/4168.index.js +0 -509
  101. package/dist/4281.index.js +0 -993
  102. package/dist/4336.index.js +0 -436
  103. package/dist/4387.index.js +0 -532
  104. package/dist/4413.index.js +0 -302
  105. package/dist/4476.index.js +0 -4510
  106. package/dist/4491.index.js +0 -133
  107. package/dist/4538.index.js +0 -185
  108. package/dist/4684.index.js +0 -319
  109. package/dist/4740.index.js +0 -165
  110. package/dist/4780.index.js +0 -209
  111. package/dist/4802.index.js +0 -225
  112. package/dist/4812.index.js +0 -379
  113. package/dist/4835.index.js +0 -126
  114. package/dist/494.index.js +0 -226
  115. package/dist/4991.index.js +0 -549
  116. package/dist/5199.index.js +0 -305
  117. package/dist/5216.index.js +0 -109
  118. package/dist/5439.index.js +0 -301
  119. package/dist/5443.index.js +0 -97
  120. package/dist/5496.index.js +0 -377
  121. package/dist/5738.index.js +0 -240
  122. package/dist/5801.index.js +0 -588
  123. package/dist/5858.index.js +0 -223
  124. package/dist/5933.index.js +0 -143
  125. package/dist/601.index.js +0 -23
  126. package/dist/6173.index.js +0 -273
  127. package/dist/6291.index.js +0 -1871
  128. package/dist/6312.index.js +0 -666
  129. package/dist/634.index.js +0 -16182
  130. package/dist/644.index.js +0 -87
  131. package/dist/6508.index.js +0 -283
  132. package/dist/6560.index.js +0 -645
  133. package/dist/6576.index.js +0 -422
  134. package/dist/6579.index.js +0 -271
  135. package/dist/6655.index.js +0 -3221
  136. package/dist/6745.index.js +0 -305
  137. package/dist/6818.index.js +0 -21642
  138. package/dist/6932.index.js +0 -1190
  139. package/dist/6972.index.js +0 -167
  140. package/dist/6995.index.js +0 -163
  141. package/dist/7249.index.js +0 -191
  142. package/dist/7372.index.js +0 -1197
  143. package/dist/7546.index.js +0 -541
  144. package/dist/76.index.js +0 -448
  145. package/dist/7879.index.js +0 -163
  146. package/dist/8025.index.js +0 -130
  147. package/dist/8054.index.js +0 -248
  148. package/dist/808.index.js +0 -1330
  149. package/dist/8097.index.js +0 -201
  150. package/dist/8126.index.js +0 -191
  151. package/dist/8178.index.js +0 -78
  152. package/dist/8382.index.js +0 -93
  153. package/dist/8408.index.js +0 -261
  154. package/dist/8540.index.js +0 -174
  155. package/dist/8635.index.js +0 -802
  156. package/dist/8688.index.js +0 -410
  157. package/dist/8699.index.js +0 -779
  158. package/dist/8891.index.js +0 -457
  159. package/dist/8916.index.js +0 -885
  160. package/dist/9146.index.js +0 -170
  161. package/dist/9168.index.js +0 -841
  162. package/dist/9292.index.js +0 -369
  163. package/dist/9422.index.js +0 -866
  164. package/dist/9440.index.js +0 -453
  165. package/dist/9479.index.js +0 -152
  166. package/dist/9481.index.js +0 -220
  167. package/dist/9539.index.js +0 -100
  168. package/dist/9547.index.js +0 -103
  169. package/dist/9692.index.js +0 -90
  170. package/dist/9800.index.js +0 -462
  171. package/dist/9899.index.js +0 -138
  172. package/dist/9981.index.js +0 -206
  173. package/dist/999.index.js +0 -117
  174. package/dist/9999.index.js +0 -1698
@@ -1,410 +0,0 @@
1
- export const id = 8688;
2
- export const ids = [8688];
3
- export const modules = {
4
-
5
- /***/ 38688:
6
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
-
8
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
- /* harmony export */ analyzePolyglotBridges: () => (/* binding */ analyzePolyglotBridges)
10
- /* harmony export */ });
11
- /* unused harmony exports BRIDGES_VERSION, blastRadius */
12
- /* harmony import */ var _secrets_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(67855);
13
- /* harmony import */ var _nix_ir_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(85337);
14
- // Polyglot and deployment/configuration bridges (X-006).
15
- //
16
- // Links an application written in Haskell to the other services it talks to, and Nix service declarations to the
17
- // application that reads their environment. A link is made ONLY from an exact, independently evidenced protocol fact:
18
- //
19
- // http a literal client URL (method + path) equals a server route, AND the target service is identified by a
20
- // matching listener port or a host equal to the service root. A path match alone is a candidate.
21
- // queue a literal queue/topic name written by a producer equals the name read by a consumer in another root over
22
- // the SAME broker technology. Different technology with one name is a gap, not a link.
23
- // store a table and column set written by one root and read by another, over the same literal database name.
24
- // env a Nix service environment variable is read by the application that service LAUNCHES (the executable or
25
- // package named in ExecStart equals the application's own name). A matching variable name alone is a candidate.
26
- //
27
- // Field paths are only attached to a LINKED bridge, and only where the two sides name the same field. A similar field
28
- // name never creates a link. Anything dynamic, ambiguous, mismatched or on an unsupported protocol is returned as a
29
- // candidate or gap with its reason, never as a proven flow.
30
- //
31
- // Source roots: the first path segment of a file is its service root ('.' for top-level files). Locations are the
32
- // original file and line. Nothing is executed or fetched; this is static source evidence ("scope": "static-source").
33
- //
34
- // Inclusion (a service's package contains an application) and data propagation are separate lists: a blast-radius or
35
- // reverse query over data links never follows an inclusion edge unless the caller asks for it.
36
-
37
-
38
-
39
-
40
- const BRIDGES_VERSION = 'language-bridges/1';
41
- const SCOPE = 'static-source';
42
- const MAX_FILE = 600_000;
43
-
44
- const langOf = (f) => (/\.l?hs$/i.test(f) ? 'haskell' : /\.(?:mjs|cjs|js|jsx|ts|tsx)$/i.test(f) ? 'javascript' : /\.py$/i.test(f) ? 'python' : /\.nix$/i.test(f) ? 'nix' : null);
45
- const rootOf = (f) => { const parts = f.split('/'); return parts.length > 1 ? parts[0] : '.'; };
46
- const lineAt = (text, idx) => { let l = 1; for (let i = 0; i < idx && i < text.length; i++) if (text.charCodeAt(i) === 10) l++; return l; };
47
- const uniq = (a) => [...new Set(a)];
48
- const METHODS = new Set(['get', 'post', 'put', 'delete', 'patch']);
49
-
50
- // ── comment stripping for C-like and Python sources (keeps offsets and newlines) ──
51
- function stripComments(text, lang) {
52
- const out = text.split('');
53
- const n = text.length;
54
- let i = 0; let str = null;
55
- while (i < n) {
56
- const c = text[i]; const d = text[i + 1];
57
- if (str) { if (c === '\\') { i += 2; continue; } if (c === str) str = null; i++; continue; }
58
- if (c === '"' || c === "'" || (c === '`' && lang === 'javascript')) { str = c; i++; continue; }
59
- if (lang === 'javascript' && c === '/' && d === '/') { while (i < n && text[i] !== '\n') { out[i] = ' '; i++; } continue; }
60
- if (lang === 'javascript' && c === '/' && d === '*') { while (i < n && !(text[i] === '*' && text[i + 1] === '/')) { if (text[i] !== '\n') out[i] = ' '; i++; } if (i < n) { out[i] = ' '; out[i + 1] = ' '; } i += 2; continue; }
61
- if (lang === 'python' && c === '#') { while (i < n && text[i] !== '\n') { out[i] = ' '; i++; } continue; }
62
- i++;
63
- }
64
- return out.join('');
65
- }
66
-
67
- // ── URL and SQL helpers ───────────────────────────────────────────────────────
68
- function parseUrl(literal) {
69
- const m = /^(?:([A-Z]+)\s+)?([a-z][a-z0-9+.-]*):\/\/([^/?#\s:]+)(?::(\d+))?(\/[^?#\s]*)?/i.exec(String(literal).trim());
70
- if (!m) return null;
71
- return { method: (m[1] || 'GET').toUpperCase(), scheme: m[2].toLowerCase(), host: m[3].toLowerCase(), port: m[4] ? Number(m[4]) : null, path: m[5] || '/' };
72
- }
73
- const SEG_PARAM = /^(?::[\w-]+|\{[\w-]+\}|<[\w:]+>|\$[\w]+)$/;
74
- function pathKey(p) { return String(p).split('/').map((s) => (SEG_PARAM.test(s) ? '*' : s)).join('/').replace(/\/+$/, '') || '/'; }
75
-
76
- const SQL_WRITE = /^\s*(?:insert\s+into|update|replace\s+into)\s+["`]?([\w.]+)["`]?/i;
77
- const SQL_READ = /^\s*select\s+([\s\S]+?)\s+from\s+["`]?([\w.]+)["`]?/i;
78
- function sqlFacts(sql) {
79
- const w = SQL_WRITE.exec(sql);
80
- if (w) {
81
- let cols = [];
82
- const ins = /^\s*(?:insert|replace)\s+into\s+["`]?[\w.]+["`]?\s*\(([^)]*)\)/i.exec(sql);
83
- if (ins) cols = ins[1].split(',').map((s) => s.trim().replace(/["`]/g, '')).filter((s) => /^\w+$/.test(s));
84
- else { const set = /\bset\s+([\s\S]+?)(?:\bwhere\b|$)/i.exec(sql); if (set) cols = [...set[1].matchAll(/["`]?(\w+)["`]?\s*=/g)].map((m) => m[1]); }
85
- return { mode: 'write', table: w[1].toLowerCase(), columns: uniq(cols.map((c) => c.toLowerCase())) };
86
- }
87
- const r = SQL_READ.exec(sql);
88
- if (r) {
89
- const raw = r[1].trim();
90
- const cols = raw === '*' ? ['*'] : raw.split(',').map((s) => s.trim().replace(/^.*\./, '').replace(/\s+as\s+.*$/i, '').replace(/["`]/g, '')).filter((s) => /^[\w*]+$/.test(s));
91
- return { mode: 'read', table: r[2].toLowerCase(), columns: uniq(cols.map((c) => c.toLowerCase())) };
92
- }
93
- return null;
94
- }
95
- const dbNameOf = (s) => { const m = /(?:dbname|database)\s*=\s*['"]?([\w-]+)/i.exec(s) || /\/\/[^/\s]+\/([\w-]+)/.exec(s); return m ? m[1].toLowerCase() : null; };
96
- const dbHostOf = (s) => { const m = /host\s*=\s*['"]?([\w.-]+)/i.exec(s) || /\/\/(?:[^@/\s]*@)?([\w.-]+)/.exec(s); return m ? m[1].toLowerCase() : null; };
97
-
98
- // ── per-language extraction ──────────────────────────────────────────────────
99
- function emptyFacts() { return { clients: [], routes: [], listeners: [], producers: [], consumers: [], sql: [], dbConns: [], envReads: [], dynamic: [], names: [] }; }
100
-
101
- function haskellFacts(file, text) {
102
- const f = emptyFacts();
103
- const toks = (0,_secrets_js__WEBPACK_IMPORTED_MODULE_0__/* .tokenizeHaskell */ .cH)(text);
104
- const imports = new Set([...text.matchAll(/^import\s+(?:qualified\s+)?([\w.]+)/gm)].map((m) => m[1]));
105
- const amqp = [...imports].some((m) => /^Network\.AMQP/.test(m));
106
- const kafka = [...imports].some((m) => /^Kafka\./.test(m));
107
- const lineOfTok = (t) => lineAt(text, t.start);
108
- const windowEnd = (i, max) => { let j = i + 1; while (j < toks.length && j - i <= max) { if (text[toks[j].start - 1] === '\n' && /\S/.test(text[toks[j].start]) && j > i + 1) break; j++; } return j; };
109
- const keysIn = (a, b, op) => { const out = []; for (let k = a; k < b - 1; k++) if (toks[k].k === 's' && toks[k + 1].k === 'o' && toks[k + 1].v === op) out.push(toks[k].v); return out; };
110
- const readsIn = (a, b) => { const out = []; for (let k = a; k < b - 1; k++) if (toks[k].k === 'o' && /^\.:\??$/.test(toks[k].v) && toks[k + 1].k === 's') out.push(toks[k + 1].v); return out; };
111
- for (let i = 0; i < toks.length; i++) {
112
- const t = toks[i];
113
- if (t.k !== 'i') continue;
114
- const base = t.v.replace(/^.*\./, '');
115
- const next = toks[i + 1];
116
- if (/^(?:parseRequest|parseRequest_|parseUrlThrow|parseUrlThrow_)$/.test(base)) {
117
- if (next && next.k === 's') {
118
- const u = parseUrl(next.v);
119
- const end = windowEnd(i, 80);
120
- if (u) f.clients.push({ file, line: lineOfTok(t), language: 'haskell', ...u, fields: uniq(keysIn(i, end, '.=')) });
121
- else f.dynamic.push({ file, line: lineOfTok(t), language: 'haskell', kind: 'http', reason: `request literal "${next.v.slice(0, 40)}" is not an absolute URL` });
122
- } else f.dynamic.push({ file, line: lineOfTok(t), language: 'haskell', kind: 'http', reason: 'dynamic endpoint: the request target is not a string literal' });
123
- } else if (METHODS.has(base) && next && next.k === 's' && next.v.startsWith('/') && /^(?:get|post|put|delete|patch)$/.test(t.v)) {
124
- const end = windowEnd(i, 120);
125
- f.routes.push({ file, line: lineOfTok(t), language: 'haskell', method: base.toUpperCase(), path: next.v, fields: uniq(readsIn(i, end)) });
126
- } else if (/^publishMsg'?$/.test(base)) {
127
- const strs = []; for (let k = i + 1; k < Math.min(toks.length, i + 8); k++) if (toks[k].k === 's') strs.push(toks[k].v);
128
- const end = windowEnd(i, 60);
129
- if (strs.length) f.producers.push({ file, line: lineOfTok(t), language: 'haskell', tech: amqp ? 'amqp' : null, name: strs.length > 1 ? strs[1] : strs[0], fields: uniq(keysIn(i - 30 < 0 ? 0 : i - 30, end, '.=')) });
130
- else f.dynamic.push({ file, line: lineOfTok(t), language: 'haskell', kind: 'queue', reason: 'dynamic queue name' });
131
- } else if (/^(?:consumeMsgs'?|getMsg|declareQueue)$/.test(base)) {
132
- const s = toks.slice(i + 1, i + 5).find((x) => x.k === 's');
133
- const end = windowEnd(i, 120);
134
- if (s) f.consumers.push({ file, line: lineOfTok(t), language: 'haskell', tech: amqp ? 'amqp' : null, name: s.v, fields: uniq(readsIn(i, end)) });
135
- } else if (base === 'TopicName' && next && next.k === 's') {
136
- const end = windowEnd(i, 60);
137
- const role = /Producer|produceMessage|ProducerRecord/.test(text) ? 'producers' : 'consumers';
138
- f[role].push({ file, line: lineOfTok(t), language: 'haskell', tech: kafka ? 'kafka' : null, name: next.v, fields: uniq(role === 'producers' ? keysIn(i - 20 < 0 ? 0 : i - 20, end, '.=') : readsIn(i, end)) });
139
- } else if (/^(?:execute|execute_|query|query_|executeMany)$/.test(base)) {
140
- const s = toks.slice(i + 1, i + 6).find((x) => x.k === 's');
141
- const facts = s ? sqlFacts(s.v) : null;
142
- if (facts) f.sql.push({ file, line: lineOfTok(t), language: 'haskell', ...facts, connection: null });
143
- } else if (/^connectPostgreSQL'?$/.test(base) && next && next.k === 's') {
144
- f.dbConns.push({ file, line: lineOfTok(t), language: 'haskell', db: dbNameOf(next.v), host: dbHostOf(next.v) });
145
- } else if (/^(?:lookupEnv|getEnv|getEnvDefault)$/.test(base) && next && next.k === 's') {
146
- f.envReads.push({ file, line: lineOfTok(t), language: 'haskell', name: next.v });
147
- }
148
- }
149
- for (const m of text.matchAll(/(?:^|[\s(])(?:run|scotty|runEnv|Warp\.run)\s+(\d{2,5})\b/gm)) f.listeners.push({ file, line: lineAt(text, m.index), language: 'haskell', port: Number(m[1]) });
150
- return f;
151
- }
152
-
153
- function jsFacts(file, raw) {
154
- const f = emptyFacts();
155
- const text = stripComments(raw, 'javascript');
156
- const amqp = /['"]amqplib['"]/.test(text); const kafka = /['"]kafkajs['"]/.test(text);
157
- const routeRe = /\b(?:app|router|server)\.(get|post|put|delete|patch)\(\s*(['"`])([^'"`]+)\2/g;
158
- const routes = [...text.matchAll(routeRe)];
159
- routes.forEach((m, idx) => {
160
- const seg = text.slice(m.index, idx + 1 < routes.length ? routes[idx + 1].index : text.length);
161
- const fields = [];
162
- for (const r of seg.matchAll(/\breq\.body\.(\w+)/g)) fields.push(r[1]);
163
- for (const r of seg.matchAll(/\breq\.body\[\s*['"](\w+)['"]\s*\]/g)) fields.push(r[1]);
164
- for (const r of seg.matchAll(/\{([^{}]*)\}\s*=\s*req\.body/g)) for (const x of r[1].split(',')) { const n = x.trim().split(/[:=\s]/)[0]; if (/^\w+$/.test(n)) fields.push(n); }
165
- f.routes.push({ file, line: lineAt(text, m.index), language: 'javascript', method: m[1].toUpperCase(), path: m[3], fields: uniq(fields) });
166
- });
167
- for (const m of text.matchAll(/\.listen\(\s*(\d{2,5})\b/g)) f.listeners.push({ file, line: lineAt(text, m.index), language: 'javascript', port: Number(m[1]) });
168
- for (const m of text.matchAll(/\b(?:fetch|axios\.(?:get|post|put|delete|patch))\(\s*(['"`])((?:https?):\/\/[^'"`]+)\1(?:\s*,\s*\{([^}]*)\})?/g)) {
169
- const u = parseUrl(m[2]); if (!u) continue;
170
- const verb = /axios\.(\w+)/.exec(m[0]); const meth = /method\s*:\s*['"](\w+)['"]/i.exec(m[3] || '');
171
- const body = (m[3] || '').match(/JSON\.stringify\(\{([^}]*)\}\)/);
172
- const seg = body ? [...body[1].matchAll(/(\w+)\s*[:,]/g)].map((x) => x[1]) : [];
173
- f.clients.push({ file, line: lineAt(text, m.index), language: 'javascript', ...u, method: (verb ? verb[1] : meth ? meth[1] : 'GET').toUpperCase(), fields: uniq(seg) });
174
- }
175
- const queueTechs = amqp ? 'amqp' : kafka ? 'kafka' : null;
176
- for (const m of text.matchAll(/\.(consume|sendToQueue)\(\s*(['"`])([^'"`]+)\2/g)) {
177
- (m[1] === 'consume' ? f.consumers : f.producers).push({ file, line: lineAt(text, m.index), language: 'javascript', tech: queueTechs, name: m[3], fields: [] });
178
- }
179
- for (const m of text.matchAll(/\.publish\(\s*(['"`])[^'"`]*\1\s*,\s*(['"`])([^'"`]+)\2/g)) f.producers.push({ file, line: lineAt(text, m.index), language: 'javascript', tech: queueTechs, name: m[3], fields: [] });
180
- for (const m of text.matchAll(/topic\s*:\s*(['"`])([^'"`]+)\1/g)) {
181
- const before = text.slice(Math.max(0, m.index - 140), m.index);
182
- (/\bsubscribe\b/.test(before) ? f.consumers : f.producers).push({ file, line: lineAt(text, m.index), language: 'javascript', tech: kafka ? 'kafka' : null, name: m[2], fields: [] });
183
- }
184
- // fields: attach message field names seen in a JSON.stringify({...}) / JSON.parse(...) variable within the call window
185
- for (const p of f.producers) { const seg = text.slice(Math.max(0, text.indexOf(p.name) - 200), text.indexOf(p.name) + 300); const o = /JSON\.stringify\(\{([^}]*)\}\)/.exec(seg); if (o) p.fields = uniq([...o[1].matchAll(/(\w+)\s*[:,]/g)].map((x) => x[1])); }
186
- for (const c of f.consumers) { const seg = text; const v = /(?:const|let|var)\s+(\w+)\s*=\s*JSON\.parse/.exec(seg); if (v) c.fields = uniq([...seg.matchAll(new RegExp(`\\b${v[1]}\\.(\\w+)`, 'g'))].map((x) => x[1])); }
187
- for (const m of text.matchAll(/\.(?:query|execute)\(\s*(['"`])([\s\S]*?)\1/g)) { const s = sqlFacts(m[2]); if (s) f.sql.push({ file, line: lineAt(text, m.index), language: 'javascript', ...s }); }
188
- for (const m of text.matchAll(/new\s+(?:Pool|Client)\(\s*\{([^}]*)\}/g)) f.dbConns.push({ file, line: lineAt(text, m.index), language: 'javascript', db: dbNameOf(`database=${(/database\s*:\s*['"]([\w-]+)/.exec(m[1]) || [])[1] || ''}`), host: ((/host\s*:\s*['"]([\w.-]+)/.exec(m[1]) || [])[1] || null) });
189
- for (const m of text.matchAll(/process\.env\.([A-Z_][A-Z0-9_]*)|process\.env\[\s*['"]([^'"]+)['"]\s*\]/g)) f.envReads.push({ file, line: lineAt(text, m.index), language: 'javascript', name: m[1] || m[2] });
190
- return f;
191
- }
192
-
193
- function pyFacts(file, raw) {
194
- const f = emptyFacts();
195
- const text = stripComments(raw, 'python');
196
- const pika = /\bimport pika\b|\bfrom pika\b/.test(text);
197
- const decos = [...text.matchAll(/@\w+\.(?:route\(\s*(['"])([^'"]+)\1(?:\s*,\s*methods\s*=\s*\[([^\]]*)\])?|(get|post|put|delete|patch)\(\s*(['"])([^'"]+)\5)/g)];
198
- decos.forEach((m, idx) => {
199
- const seg = text.slice(m.index, idx + 1 < decos.length ? decos[idx + 1].index : text.length);
200
- const fields = [];
201
- for (const r of seg.matchAll(/(?:request\.(?:json|get_json\(\))|data|payload|body)\s*\[\s*['"](\w+)['"]\s*\]/g)) fields.push(r[1]);
202
- for (const r of seg.matchAll(/(?:request\.(?:json|get_json\(\))|data|payload|body)\.get\(\s*['"](\w+)['"]/g)) fields.push(r[1]);
203
- const path = m[2] || m[6];
204
- const methods = m[4] ? [m[4].toUpperCase()] : (m[3] ? [...m[3].matchAll(/['"](\w+)['"]/g)].map((x) => x[1].toUpperCase()) : ['GET']);
205
- for (const method of methods) f.routes.push({ file, line: lineAt(text, m.index), language: 'python', method, path, fields: uniq(fields) });
206
- });
207
- for (const m of text.matchAll(/\b(?:app|uvicorn)\.run\([^)]*?\bport\s*=\s*(\d{2,5})/g)) f.listeners.push({ file, line: lineAt(text, m.index), language: 'python', port: Number(m[1]) });
208
- for (const m of text.matchAll(/requests\.(get|post|put|delete|patch)\(\s*(['"])(https?:\/\/[^'"]+)\2([^)]*)\)/g)) {
209
- const u = parseUrl(m[3]); if (!u) continue;
210
- const js = /json\s*=\s*\{([^}]*)\}/.exec(m[4] || '');
211
- f.clients.push({ file, line: lineAt(text, m.index), language: 'python', ...u, method: m[1].toUpperCase(), fields: js ? uniq([...js[1].matchAll(/['"](\w+)['"]\s*:/g)].map((x) => x[1])) : [] });
212
- }
213
- for (const m of text.matchAll(/basic_consume\([^)]*?queue\s*=\s*(['"])([^'"]+)\1/g)) f.consumers.push({ file, line: lineAt(text, m.index), language: 'python', tech: pika ? 'amqp' : null, name: m[2], fields: [] });
214
- for (const m of text.matchAll(/basic_publish\([^)]*?routing_key\s*=\s*(['"])([^'"]+)\1/g)) f.producers.push({ file, line: lineAt(text, m.index), language: 'python', tech: pika ? 'amqp' : null, name: m[2], fields: [] });
215
- for (const c of f.consumers) { const seg = text; const v = /(\w+)\s*=\s*json\.loads/.exec(seg); if (v) c.fields = uniq([...seg.matchAll(new RegExp(`\\b${v[1]}\\[\\s*['"](\\w+)['"]\\s*\\]|\\b${v[1]}\\.get\\(\\s*['"](\\w+)['"]`, 'g'))].map((x) => x[1] || x[2])); }
216
- for (const m of text.matchAll(/\.execute\(\s*(['"]{1,3})([\s\S]*?)\1/g)) { const s = sqlFacts(m[2]); if (s) f.sql.push({ file, line: lineAt(text, m.index), language: 'python', ...s }); }
217
- for (const m of text.matchAll(/\.connect\(([^)]*)\)/g)) { if (!/dbname|database/.test(m[1])) continue; f.dbConns.push({ file, line: lineAt(text, m.index), language: 'python', db: dbNameOf(m[1].replace(/['"]/g, '').replace(/,\s*/g, ' ').replace(/\bdatabase\s*=/, 'database=')), host: dbHostOf(m[1].replace(/['"]/g, '').replace(/,\s*/g, ' ')) }); }
218
- for (const m of text.matchAll(/os\.environ\[\s*['"]([^'"]+)['"]\s*\]|os\.environ\.get\(\s*['"]([^'"]+)['"]|os\.getenv\(\s*['"]([^'"]+)['"]/g)) f.envReads.push({ file, line: lineAt(text, m.index), language: 'python', name: m[1] || m[2] || m[3] });
219
- return f;
220
- }
221
-
222
- /** Application identity per root, from manifests only (never from directory guesswork alone beyond the root name). */
223
- function appNames(files) {
224
- const out = new Map();
225
- const add = (root, name) => { if (!name) return; if (!out.has(root)) out.set(root, new Set()); out.get(root).add(String(name).toLowerCase()); };
226
- for (const [file, text] of Object.entries(files)) {
227
- const root = rootOf(file);
228
- if (/\.cabal$/i.test(file)) { for (const m of String(text).matchAll(/^\s*(?:executable|name)\s*:?\s+([\w-]+)/gim)) add(root, m[1]); }
229
- else if (/(?:^|\/)package\.ya?ml$/i.test(file)) { for (const m of String(text).matchAll(/^name:\s*([\w-]+)/gm)) add(root, m[1]); const ex = /^executables:\s*\n((?:[ \t]+.*\n?)*)/m.exec(text); if (ex) for (const m of ex[1].matchAll(/^[ \t]{2}([\w-]+):/gm)) add(root, m[1]); }
230
- else if (/(?:^|\/)package\.json$/i.test(file)) { try { add(root, JSON.parse(text).name); } catch { /* malformed manifest: no identity */ } }
231
- else if (/(?:^|\/)pyproject\.toml$/i.test(file)) { const m = /^name\s*=\s*['"]([\w-]+)['"]/m.exec(text); if (m) add(root, m[1]); }
232
- }
233
- return out;
234
- }
235
-
236
- function nixServices(files) {
237
- const services = [];
238
- for (const [file, text] of Object.entries(files)) {
239
- if (!/\.nix$/i.test(file)) continue;
240
- let ir; try { ir = (0,_nix_ir_js__WEBPACK_IMPORTED_MODULE_1__/* .analyzeNix */ .KL)(text, { file }).ir; } catch { continue; }
241
- const by = new Map();
242
- for (const b of ir.bindings || []) {
243
- const p = b.path || [];
244
- const si = p.indexOf('services');
245
- if (p[0] !== 'systemd' || si !== 1 || !p[2]) continue;
246
- const name = p[2];
247
- if (!by.has(name)) by.set(name, { name, file, line: b.span.startLine, env: {}, environmentFile: false, exec: null, pkg: null, exe: null, port: null, dynamic: false });
248
- const s = by.get(name); const rest = p.slice(3).join('.');
249
- if (/^environment\.[A-Za-z_][\w]*$/.test(rest)) s.env[p[4]] = { line: b.span.startLine, value: b.value && b.value.literal != null ? b.value.literal : null };
250
- else if (/EnvironmentFile$/.test(rest)) s.environmentFile = true;
251
- else if (/(?:^|\.)ExecStart$/.test(rest) || rest === 'script') {
252
- s.exec = text.slice(b.valueSpan.startOffset, b.valueSpan.endOffset);
253
- const interp = (b.value && b.value.interpolations || []).map((x) => x.text);
254
- const pk = interp.map((t) => /^pkgs\.([\w-]+)/.exec(t)).find(Boolean); if (pk) s.pkg = pk[1].toLowerCase();
255
- const exe = /\/bin\/([\w.-]+)/.exec(s.exec); if (exe) s.exe = exe[1].toLowerCase();
256
- const port = /--port[ =](\d{2,5})/.exec(s.exec); if (port) s.port = Number(port[1]);
257
- if (rest === 'script') { s.dynamic = true; }
258
- }
259
- if (b.dynamic) s.dynamic = true;
260
- }
261
- services.push(...by.values());
262
- }
263
- for (const s of services) if (s.port == null && s.env.PORT && /^\d+$/.test(String(s.env.PORT.value))) s.port = Number(s.env.PORT.value);
264
- return services;
265
- }
266
-
267
- const loc = (x) => ({ file: x.file, line: x.line, language: x.language, root: rootOf(x.file) });
268
-
269
- /**
270
- * @param {Record<string,string>} files every source/manifest/Nix file handed to the scan
271
- * @returns {{version, scope, services, inclusions, bridges, candidates, gaps, limits}}
272
- */
273
- function analyzePolyglotBridges(files) {
274
- const all = {};
275
- for (const [f, t] of Object.entries(files || {})) if (typeof t === 'string' && t.length <= MAX_FILE) all[f] = t;
276
- const facts = emptyFacts();
277
- const merge = (x) => { for (const k of Object.keys(facts)) facts[k].push(...x[k]); };
278
- for (const [file, text] of Object.entries(all)) {
279
- const lang = langOf(file);
280
- try { if (lang === 'haskell') merge(haskellFacts(file, text)); else if (lang === 'javascript') merge(jsFacts(file, text)); else if (lang === 'python') merge(pyFacts(file, text)); } catch { /* one file's failure never hides the others */ }
281
- }
282
- const names = appNames(all);
283
- const services = nixServices(all);
284
- const bridges = []; const candidates = []; const gaps = [];
285
- const push = (list, o) => list.push({ scope: SCOPE, ...o });
286
-
287
- // listener ports per root
288
- const portsByRoot = new Map();
289
- for (const l of facts.listeners) { const r = rootOf(l.file); if (!portsByRoot.has(r)) portsByRoot.set(r, new Set()); portsByRoot.get(r).add(l.port); }
290
- const rootsOnPort = (port) => [...portsByRoot.entries()].filter(([, s]) => s.has(port)).map(([r]) => r);
291
- const allRoots = new Set(Object.keys(all).map(rootOf));
292
-
293
- // ── http ────────────────────────────────────────────────────────────────────
294
- for (const d of facts.dynamic) push(gaps, { kind: d.kind, status: 'gap', reason: d.reason, from: loc(d), evidence: [] });
295
- for (const c of facts.clients) {
296
- const from = loc(c);
297
- if (!/^https?$/.test(c.scheme)) { push(gaps, { kind: 'http', status: 'gap', reason: `unsupported protocol "${c.scheme}"`, from, evidence: [] }); continue; }
298
- const key = pathKey(c.path);
299
- const sameRoute = facts.routes.filter((r) => rootOf(r.file) !== from.root && pathKey(r.path) === key);
300
- const matching = sameRoute.filter((r) => r.method === c.method);
301
- if (!matching.length) {
302
- if (sameRoute.length) push(gaps, { kind: 'http', status: 'gap', reason: `method mismatch: client ${c.method} ${c.path}, server offers ${sameRoute.map((r) => r.method).join('/')}`, from, evidence: [] });
303
- else if (c.port != null && rootsOnPort(c.port).filter((r) => r !== from.root).length) push(gaps, { kind: 'http', status: 'gap', reason: `schema mismatch: a service listens on port ${c.port} but declares no ${c.method} ${c.path}`, from, evidence: [`listener port ${c.port}`] });
304
- else push(gaps, { kind: 'http', status: 'gap', reason: 'unknown endpoint: no server in the provided roots declares this route', from, evidence: [] });
305
- continue;
306
- }
307
- const identified = matching.filter((r) => { const root = rootOf(r.file); return (c.port != null && (portsByRoot.get(root) || new Set()).has(c.port)) || c.host === root.toLowerCase(); });
308
- const targetRoots = uniq(matching.map((r) => rootOf(r.file)));
309
- if (identified.length === 1 && uniq(identified.map((r) => rootOf(r.file))).length === 1) {
310
- const s = identified[0];
311
- const clientFields = c.fields; const serverFields = s.fields;
312
- const shared = clientFields.filter((x) => serverFields.includes(x));
313
- const root = rootOf(s.file);
314
- const evidence = [`literal route ${c.method} ${c.path} matches ${s.method} ${s.path}`, c.port != null && (portsByRoot.get(root) || new Set()).has(c.port) ? `client port ${c.port} equals the listener port of root "${root}"` : `client host "${c.host}" names root "${root}"`];
315
- push(bridges, { kind: 'http', status: 'linked', protocol: 'http', confidence: 'high', from, to: loc(s), fields: shared.map((name) => ({ name, label: 'same field name on a linked endpoint', from: { file: c.file, line: c.line }, to: { file: s.file, line: s.line } })), clientOnlyFields: clientFields.filter((x) => !serverFields.includes(x)), serverOnlyFields: serverFields.filter((x) => !clientFields.includes(x)), evidence });
316
- } else if (identified.length > 1) {
317
- push(candidates, { kind: 'http', status: 'candidate', reason: 'ambiguous service mapping: more than one service matches the route and port', from, to: identified.map(loc), evidence: [`literal route ${c.method} ${c.path}`] });
318
- } else {
319
- push(candidates, { kind: 'http', status: 'candidate', reason: targetRoots.length > 1 ? 'ambiguous service mapping: several roots declare this route and none is identified by port or host' : 'the route matches but the service is not identified by a listener port or host name', from, to: matching.map(loc), evidence: [`literal route ${c.method} ${c.path}`] });
320
- }
321
- }
322
-
323
- // ── queues ──────────────────────────────────────────────────────────────────
324
- for (const p of facts.producers) {
325
- const from = loc(p);
326
- const sameName = facts.consumers.filter((c) => c.name === p.name && rootOf(c.file) !== from.root);
327
- if (!sameName.length) { push(gaps, { kind: 'queue', status: 'gap', reason: `no consumer of "${p.name}" in another root`, from, evidence: [] }); continue; }
328
- const sameTech = sameName.filter((c) => c.tech && p.tech && c.tech === p.tech);
329
- if (!sameTech.length) { push(gaps, { kind: 'queue', status: 'gap', reason: `a consumer reads "${p.name}" over ${sameName[0].tech || 'an unrecognised broker'} but this producer uses ${p.tech || 'an unrecognised broker'}: different or unsupported protocol`, from, to: sameName.map(loc), evidence: [] }); continue; }
330
- if (uniq(sameTech.map((c) => rootOf(c.file))).length > 1) { push(candidates, { kind: 'queue', status: 'candidate', reason: 'ambiguous: several roots consume this queue name', from, to: sameTech.map(loc), evidence: [`queue "${p.name}" over ${p.tech}`] }); continue; }
331
- const c = sameTech[0];
332
- const shared = p.fields.filter((x) => c.fields.includes(x));
333
- push(bridges, { kind: 'queue', status: 'linked', protocol: p.tech, confidence: 'medium', from, to: loc(c), queue: p.name, fields: shared.map((name) => ({ name, label: 'same field name on a linked queue', from: { file: p.file, line: p.line }, to: { file: c.file, line: c.line } })), producerOnlyFields: p.fields.filter((x) => !c.fields.includes(x)), consumerOnlyFields: c.fields.filter((x) => !p.fields.includes(x)), evidence: [`literal queue "${p.name}" over ${p.tech}`], limitations: ['broker host identity is not verified from source'] });
334
- }
335
-
336
- // ── stores ──────────────────────────────────────────────────────────────────
337
- const connOf = (rootName) => facts.dbConns.filter((d) => rootOf(d.file) === rootName);
338
- for (const w of facts.sql.filter((s) => s.mode === 'write')) {
339
- const wr = rootOf(w.file);
340
- const readers = facts.sql.filter((s) => s.mode === 'read' && s.table === w.table && rootOf(s.file) !== wr);
341
- if (!readers.length) continue;
342
- for (const r of readers) {
343
- const cols = r.columns.includes('*') ? w.columns : r.columns.filter((c) => w.columns.includes(c));
344
- const wc = connOf(wr); const rc = connOf(rootOf(r.file));
345
- const wdb = uniq(wc.map((d) => d.db).filter(Boolean)); const rdb = uniq(rc.map((d) => d.db).filter(Boolean));
346
- const from = loc(w); const to = loc(r);
347
- if (!cols.length) { push(gaps, { kind: 'store', status: 'gap', reason: `table "${w.table}" is shared but the written and read column sets do not intersect`, from, to, evidence: [] }); continue; }
348
- if (wdb.length === 1 && rdb.length === 1 && wdb[0] === rdb[0]) {
349
- push(bridges, { kind: 'store', status: 'linked', protocol: 'sql', confidence: 'medium', from, to, table: w.table, database: wdb[0], fields: cols.map((name) => ({ name: `${w.table}.${name}`, label: 'same table and column in the same literal database', from: { file: w.file, line: w.line }, to: { file: r.file, line: r.line } })), evidence: [`both roots connect to database "${wdb[0]}"`, `table "${w.table}" written then read`], limitations: ['database host identity is not verified from source'] });
350
- } else {
351
- push(candidates, { kind: 'store', status: 'candidate', reason: wdb.length && rdb.length && wdb[0] !== rdb[0] ? `different databases ("${wdb[0]}" and "${rdb[0]}")` : 'database identity is not stated by both sides', from, to, table: w.table, evidence: [`table "${w.table}" with columns ${cols.join(', ')}`] });
352
- }
353
- }
354
- }
355
-
356
- // ── Nix env/launch -> application read, plus inclusion ───────────────────────
357
- const inclusions = [];
358
- for (const s of services) {
359
- const owners = [...names.entries()].filter(([, set]) => (s.exe && set.has(s.exe)) || (s.pkg && set.has(s.pkg))).map(([r]) => r);
360
- for (const r of owners) inclusions.push({ kind: 'service-includes-application', service: s.name, root: r, via: s.exe ? `ExecStart executable ${s.exe}` : `package ${s.pkg}`, from: { file: s.file, line: s.line, language: 'nix', root: rootOf(s.file) } });
361
- if (s.environmentFile) push(gaps, { kind: 'env', status: 'gap', reason: `service "${s.name}" uses EnvironmentFile: its contents are not read`, from: { file: s.file, line: s.line, language: 'nix', root: rootOf(s.file) }, evidence: [] });
362
- if (s.dynamic && !s.exe) push(gaps, { kind: 'env', status: 'gap', reason: `service "${s.name}" launches through a generated script: the executable is not resolved statically`, from: { file: s.file, line: s.line, language: 'nix', root: rootOf(s.file) }, evidence: [] });
363
- for (const [varName, info] of Object.entries(s.env)) {
364
- const readers = facts.envReads.filter((e) => e.name === varName);
365
- if (!readers.length) continue;
366
- const from = { file: s.file, line: info.line, language: 'nix', root: rootOf(s.file) };
367
- const owned = readers.filter((e) => owners.includes(rootOf(e.file)));
368
- if (owned.length) {
369
- for (const e of owned) push(bridges, { kind: 'env', status: 'linked', protocol: 'environment', confidence: 'high', from, to: loc(e), service: s.name, fields: [{ name: varName, label: 'service environment variable read by the application it launches', from: { file: s.file, line: info.line }, to: { file: e.file, line: e.line } }], valueKnown: info.value !== null, evidence: [`service "${s.name}" launches ${s.exe ? `executable "${s.exe}"` : `package "${s.pkg}"`}, the application of root "${rootOf(e.file)}"`] });
370
- } else {
371
- for (const e of readers) push(candidates, { kind: 'env', status: 'candidate', reason: owners.length ? `the service launches a different application than root "${rootOf(e.file)}"` : 'the variable name matches but the service does not identify the application it launches', from, to: loc(e), service: s.name, evidence: [`environment variable ${varName}`] });
372
- }
373
- }
374
- }
375
-
376
- const bySort = (a, b) => (a.from.file + a.from.line).localeCompare(b.from.file + b.from.line) || a.kind.localeCompare(b.kind);
377
- bridges.sort(bySort); candidates.sort(bySort); gaps.sort(bySort);
378
- return {
379
- version: BRIDGES_VERSION, scope: SCOPE,
380
- services: services.map((s) => ({ name: s.name, file: s.file, line: s.line, executable: s.exe, package: s.pkg, port: s.port })),
381
- inclusions, bridges, candidates, gaps,
382
- limits: ['source roots are the first path segment; a service with no distinct root cannot be linked', 'schema documents (OpenAPI, GraphQL, gRPC) are not required: links come from literal routes, queue names, tables and launch declarations', `${allRoots.size} root(s) considered`],
383
- };
384
- }
385
-
386
- /**
387
- * Roots reachable from `root` over EVIDENCED data links only. `direction`: 'downstream' follows data written by the
388
- * root, 'upstream' follows who sends data to it. Candidates, gaps and inclusions are never followed unless
389
- * `includeInclusions` is true, and then they are reported separately from the data roots.
390
- */
391
- function blastRadius(result, root, { direction = 'downstream', includeInclusions = false } = {}) {
392
- const seen = new Set([root]); const queue = [root]; const edges = [];
393
- while (queue.length) {
394
- const cur = queue.shift();
395
- for (const b of result.bridges) {
396
- const a = b.from.root; const z = b.to.root;
397
- const [src, dst] = direction === 'downstream' ? [a, z] : [z, a];
398
- if (src !== cur || seen.has(dst)) continue;
399
- seen.add(dst); queue.push(dst); edges.push({ from: src, to: dst, kind: b.kind });
400
- }
401
- }
402
- const out = { roots: [...seen].filter((r) => r !== root).sort(), edges, inclusions: [] };
403
- if (includeInclusions) out.inclusions = result.inclusions.filter((i) => seen.has(i.root));
404
- return out;
405
- }
406
-
407
-
408
- /***/ })
409
-
410
- };