@clear-capabilities/agentic-security-scanner 0.172.0 → 0.173.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.
- package/CHANGELOG.md +29 -0
- package/bin/agentic-security.js +37 -0
- package/dist/119.index.js +197 -0
- package/dist/128.index.js +129 -0
- package/dist/1293.index.js +5689 -0
- package/dist/1336.index.js +101 -101
- package/dist/1351.index.js +133 -0
- package/dist/1387.index.js +271 -0
- package/dist/1437.index.js +23 -0
- package/dist/1445.index.js +110 -0
- package/dist/1505.index.js +151 -0
- package/dist/1557.index.js +293 -0
- package/dist/1621.index.js +311 -0
- package/dist/1751.index.js +160 -0
- package/dist/1765.index.js +727 -0
- package/dist/1861.index.js +690 -0
- package/dist/1898.index.js +116 -0
- package/dist/1906.index.js +433 -0
- package/dist/1920.index.js +1 -291
- package/dist/208.index.js +1631 -0
- package/dist/2199.index.js +0 -239
- package/dist/2223.index.js +159 -0
- package/dist/2530.index.js +152 -0
- package/dist/2565.index.js +116 -0
- package/dist/2574.index.js +127 -0
- package/dist/2620.index.js +345 -0
- package/dist/2773.index.js +98 -0
- package/dist/2775.index.js +32 -0
- package/dist/2966.index.js +171 -0
- package/dist/2972.index.js +87 -0
- package/dist/2991.index.js +131 -0
- package/dist/3063.index.js +833 -0
- package/dist/3075.index.js +227 -0
- package/dist/3121.index.js +297 -0
- package/dist/3314.index.js +263 -0
- package/dist/3480.index.js +1822 -0
- package/dist/3481.index.js +24 -0
- package/dist/3506.index.js +268 -0
- package/dist/3533.index.js +591 -0
- package/dist/3653.index.js +450 -0
- package/dist/3822.index.js +131 -0
- package/dist/3868.index.js +292 -0
- package/dist/3917.index.js +152 -0
- package/dist/3918.index.js +192 -0
- package/dist/4090.index.js +288 -0
- package/dist/4121.index.js +1190 -0
- package/dist/4142.index.js +0 -239
- package/dist/4336.index.js +436 -0
- package/dist/4387.index.js +532 -0
- package/dist/4413.index.js +302 -0
- package/dist/4476.index.js +4510 -0
- package/dist/4491.index.js +133 -0
- package/dist/4538.index.js +185 -0
- package/dist/4684.index.js +319 -0
- package/dist/4740.index.js +165 -0
- package/dist/4780.index.js +209 -0
- package/dist/4802.index.js +225 -0
- package/dist/4812.index.js +379 -0
- package/dist/4835.index.js +126 -0
- package/dist/494.index.js +226 -0
- package/dist/4991.index.js +549 -0
- package/dist/5199.index.js +305 -0
- package/dist/5216.index.js +109 -0
- package/dist/5439.index.js +301 -0
- package/dist/5443.index.js +97 -0
- package/dist/5496.index.js +377 -0
- package/dist/550.index.js +2 -1
- package/dist/5801.index.js +588 -0
- package/dist/5858.index.js +223 -0
- package/dist/5933.index.js +143 -0
- package/dist/601.index.js +23 -0
- package/dist/6173.index.js +273 -0
- package/dist/6291.index.js +1871 -0
- package/dist/6312.index.js +666 -0
- package/dist/634.index.js +16182 -0
- package/dist/644.index.js +87 -0
- package/dist/6508.index.js +283 -0
- package/dist/6560.index.js +645 -0
- package/dist/6576.index.js +422 -0
- package/dist/6579.index.js +271 -0
- package/dist/6745.index.js +305 -0
- package/dist/6818.index.js +21642 -0
- package/dist/6972.index.js +167 -0
- package/dist/6995.index.js +163 -0
- package/dist/7249.index.js +191 -0
- package/dist/7372.index.js +1197 -0
- package/dist/7405.index.js +23 -6
- package/dist/7546.index.js +541 -0
- package/dist/76.index.js +448 -0
- package/dist/7879.index.js +163 -0
- package/dist/8025.index.js +130 -0
- package/dist/8054.index.js +248 -0
- package/dist/8097.index.js +201 -0
- package/dist/8126.index.js +191 -0
- package/dist/8178.index.js +78 -0
- package/dist/818.index.js +212 -0
- package/dist/8382.index.js +93 -0
- package/dist/8408.index.js +261 -0
- package/dist/8540.index.js +174 -0
- package/dist/8635.index.js +802 -0
- package/dist/8688.index.js +410 -0
- package/dist/8699.index.js +779 -0
- package/dist/8891.index.js +457 -0
- package/dist/8916.index.js +885 -0
- package/dist/9146.index.js +170 -0
- package/dist/9168.index.js +841 -0
- package/dist/9292.index.js +369 -0
- package/dist/9382.index.js +338 -48
- package/dist/9422.index.js +866 -0
- package/dist/9440.index.js +453 -0
- package/dist/9479.index.js +152 -0
- package/dist/9481.index.js +220 -0
- package/dist/9539.index.js +100 -0
- package/dist/9547.index.js +103 -0
- package/dist/9560.index.js +41 -61
- package/dist/9692.index.js +90 -0
- package/dist/9800.index.js +213 -1
- package/dist/9899.index.js +138 -0
- package/dist/9981.index.js +206 -0
- package/dist/999.index.js +117 -0
- package/dist/agentic-security.mjs +28 -28
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/package.json +31 -6
- package/src/context-intelligence/CLAUDE.md +4 -0
- package/src/context-intelligence/adapters/haskell-hie.js +28 -1
- package/src/context-intelligence/candidates.js +2 -1
- package/src/context-intelligence/canonical.js +25 -0
- package/src/context-intelligence/capabilities.js +2 -1
- package/src/context-intelligence/cli.js +16 -10
- package/src/context-intelligence/config.js +4 -1
- package/src/context-intelligence/controls.js +108 -10
- package/src/context-intelligence/counterexample.js +200 -0
- package/src/context-intelligence/cross-route.js +111 -0
- package/src/context-intelligence/entrypoints.js +2 -2
- package/src/context-intelligence/evaluation/index.js +11 -4
- package/src/context-intelligence/evaluation/scripted-reader.js +12 -2
- package/src/context-intelligence/findings.js +166 -0
- package/src/context-intelligence/invariants.js +197 -0
- package/src/context-intelligence/queue.js +6 -1
- package/src/context-intelligence/reachability.js +10 -4
- package/src/context-intelligence/review.js +129 -16
- package/src/dataflow/access-paths.js +11 -0
- package/src/dataflow/analysis-limits.js +66 -0
- package/src/dataflow/engine.js +272 -20
- package/src/dataflow/service-edges.js +174 -0
- package/src/dataflow/summaries.js +7 -1
- package/src/discovery/judge.js +2 -1
- package/src/engine.js +82 -14
- package/src/fix/apply-fix-service.js +55 -8
- package/src/fix/batch-journal.js +84 -0
- package/src/fix/exploit-replay.js +51 -0
- package/src/fix/footprint.js +65 -0
- package/src/fix/patch-policy.js +49 -0
- package/src/fix/secret-persistence.js +39 -0
- package/src/fix/test-commands.js +84 -0
- package/src/fix/verification-adapters.js +97 -0
- package/src/fix/verification-record.js +243 -0
- package/src/fix/verify-patch.js +89 -0
- package/src/ir/CLAUDE.md +5 -0
- package/src/ir/callgraph.js +23 -1
- package/src/ir/module-resolver.js +315 -0
- package/src/ir/parser-js.js +21 -2
- package/src/ir/semantic-graph.js +245 -0
- package/src/lineage/build-attested-correlation.js +63 -0
- package/src/lineage/deployment-identity.js +76 -0
- package/src/mcp/tools.js +13 -34
- package/src/pipeline/canonical-output.js +64 -0
- package/src/pipeline/detector-runner.js +7 -0
- package/src/pipeline/scan-health.js +14 -0
- package/src/pipeline/supervised-analyzers.js +125 -0
- package/src/pipeline/supervised-child.js +17 -0
- package/src/pipeline/telemetry.js +79 -0
- package/src/posture/accuracy-scorecard.js +98 -9
- package/src/posture/artifact-registry.js +5 -0
- package/src/posture/assurance/evidence-registry.js +215 -0
- package/src/posture/assurance/release-package-verify.js +135 -0
- package/src/posture/assurance/release-package.js +118 -0
- package/src/posture/assurance/release-verdict.js +94 -0
- package/src/posture/assurance/waiver.js +200 -0
- package/src/posture/compliance-truth.js +100 -0
- package/src/posture/evaluation/scan-child.js +3 -1
- package/src/posture/evaluation/why-missed.js +3 -1
- package/src/posture/exploitability-evidence.js +141 -0
- package/src/posture/fix-verify.js +4 -2
- package/src/posture/fleet/exposure-ranking.js +115 -0
- package/src/posture/fleet/service-chain-graph.js +150 -0
- package/src/posture/graph-reconciliation.js +154 -0
- package/src/posture/provenance/coverage.js +103 -0
- package/src/posture/provenance/git-evidence.js +84 -0
- package/src/posture/provenance/origin-resolver.js +7 -1
- package/src/posture/provenance/predicate-replay.js +14 -4
- package/src/posture/runtime-correlation.js +61 -15
- package/src/posture/runtime-explanation.js +116 -0
- package/src/posture/runtime-trace-ingest.js +194 -0
- package/src/posture/scan-checkpoint.js +38 -10
- package/src/posture/waf-ingest.js +7 -2
- package/src/report/index.js +4 -0
- package/src/report/oscal.js +38 -0
- package/src/report/perspectives.js +150 -0
- package/src/sast/_comment-strip.js +8 -1
- package/src/sast/ruby.js +26 -0
- package/src/util/string-memo.js +38 -0
|
@@ -0,0 +1,410 @@
|
|
|
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
|
+
};
|