@vinkius-core/mcp-fusion 2.7.0 → 2.8.1
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/dist/cli/fusion.d.ts +101 -0
- package/dist/cli/fusion.d.ts.map +1 -0
- package/dist/cli/fusion.js +333 -0
- package/dist/cli/fusion.js.map +1 -0
- package/dist/index.d.ts +41 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -1
- package/dist/introspection/BehaviorDigest.d.ts +112 -0
- package/dist/introspection/BehaviorDigest.d.ts.map +1 -0
- package/dist/introspection/BehaviorDigest.js +147 -0
- package/dist/introspection/BehaviorDigest.js.map +1 -0
- package/dist/introspection/CapabilityLockfile.d.ts +261 -0
- package/dist/introspection/CapabilityLockfile.d.ts.map +1 -0
- package/dist/introspection/CapabilityLockfile.js +392 -0
- package/dist/introspection/CapabilityLockfile.js.map +1 -0
- package/dist/introspection/ContractAwareSelfHealing.d.ts +90 -0
- package/dist/introspection/ContractAwareSelfHealing.d.ts.map +1 -0
- package/dist/introspection/ContractAwareSelfHealing.js +132 -0
- package/dist/introspection/ContractAwareSelfHealing.js.map +1 -0
- package/dist/introspection/ContractDiff.d.ts +91 -0
- package/dist/introspection/ContractDiff.d.ts.map +1 -0
- package/dist/introspection/ContractDiff.js +466 -0
- package/dist/introspection/ContractDiff.js.map +1 -0
- package/dist/introspection/CryptoAttestation.d.ts +143 -0
- package/dist/introspection/CryptoAttestation.d.ts.map +1 -0
- package/dist/introspection/CryptoAttestation.js +194 -0
- package/dist/introspection/CryptoAttestation.js.map +1 -0
- package/dist/introspection/EntitlementScanner.d.ts +177 -0
- package/dist/introspection/EntitlementScanner.d.ts.map +1 -0
- package/dist/introspection/EntitlementScanner.js +459 -0
- package/dist/introspection/EntitlementScanner.js.map +1 -0
- package/dist/introspection/GovernanceObserver.d.ts +88 -0
- package/dist/introspection/GovernanceObserver.d.ts.map +1 -0
- package/dist/introspection/GovernanceObserver.js +132 -0
- package/dist/introspection/GovernanceObserver.js.map +1 -0
- package/dist/introspection/SemanticProbe.d.ts +207 -0
- package/dist/introspection/SemanticProbe.d.ts.map +1 -0
- package/dist/introspection/SemanticProbe.js +255 -0
- package/dist/introspection/SemanticProbe.js.map +1 -0
- package/dist/introspection/TokenEconomics.d.ts +210 -0
- package/dist/introspection/TokenEconomics.d.ts.map +1 -0
- package/dist/introspection/TokenEconomics.js +286 -0
- package/dist/introspection/TokenEconomics.js.map +1 -0
- package/dist/introspection/ToolContract.d.ts +161 -0
- package/dist/introspection/ToolContract.d.ts.map +1 -0
- package/dist/introspection/ToolContract.js +192 -0
- package/dist/introspection/ToolContract.js.map +1 -0
- package/dist/introspection/canonicalize.d.ts +20 -0
- package/dist/introspection/canonicalize.d.ts.map +1 -0
- package/dist/introspection/canonicalize.js +51 -0
- package/dist/introspection/canonicalize.js.map +1 -0
- package/dist/introspection/index.d.ts +20 -0
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +20 -0
- package/dist/introspection/index.js.map +1 -1
- package/dist/observability/DebugObserver.d.ts +26 -1
- package/dist/observability/DebugObserver.d.ts.map +1 -1
- package/dist/observability/DebugObserver.js +8 -1
- package/dist/observability/DebugObserver.js.map +1 -1
- package/dist/observability/index.d.ts +1 -1
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js.map +1 -1
- package/dist/server/ServerAttachment.d.ts +41 -0
- package/dist/server/ServerAttachment.d.ts.map +1 -1
- package/dist/server/ServerAttachment.js +25 -1
- package/dist/server/ServerAttachment.js.map +1 -1
- package/package.json +8 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entitlement detection patterns.
|
|
3
|
+
*
|
|
4
|
+
* Conservative: may over-report (false positives in comments/strings)
|
|
5
|
+
* but never under-report. This is intentional — security analysis
|
|
6
|
+
* should err on the side of caution.
|
|
7
|
+
*/
|
|
8
|
+
const PATTERNS = [
|
|
9
|
+
// ── Filesystem ──
|
|
10
|
+
{ category: 'filesystem', identifier: 'fs', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?fs(?:\/promises)?['"]/g },
|
|
11
|
+
{ category: 'filesystem', identifier: 'fs.*', regex: /\bfs\.\w+(?:Sync)?\s*\(/g },
|
|
12
|
+
{ category: 'filesystem', identifier: 'readFile', regex: /\breadFile(?:Sync)?\s*\(/g },
|
|
13
|
+
{ category: 'filesystem', identifier: 'writeFile', regex: /\bwriteFile(?:Sync)?\s*\(/g },
|
|
14
|
+
{ category: 'filesystem', identifier: 'appendFile', regex: /\bappendFile(?:Sync)?\s*\(/g },
|
|
15
|
+
{ category: 'filesystem', identifier: 'unlink', regex: /\bunlink(?:Sync)?\s*\(/g },
|
|
16
|
+
{ category: 'filesystem', identifier: 'rmdir', regex: /\brmdir(?:Sync)?\s*\(/g },
|
|
17
|
+
{ category: 'filesystem', identifier: 'mkdir', regex: /\bmkdir(?:Sync)?\s*\(/g },
|
|
18
|
+
{ category: 'filesystem', identifier: 'rename', regex: /\brename(?:Sync)?\s*\(/g },
|
|
19
|
+
{ category: 'filesystem', identifier: 'copyFile', regex: /\bcopyFile(?:Sync)?\s*\(/g },
|
|
20
|
+
{ category: 'filesystem', identifier: 'createReadStream', regex: /\bcreateReadStream\s*\(/g },
|
|
21
|
+
{ category: 'filesystem', identifier: 'createWriteStream', regex: /\bcreateWriteStream\s*\(/g },
|
|
22
|
+
// ── Network ──
|
|
23
|
+
{ category: 'network', identifier: 'fetch', regex: /\bfetch\s*\(/g },
|
|
24
|
+
{ category: 'network', identifier: 'http', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?https?['"]/g },
|
|
25
|
+
{ category: 'network', identifier: 'axios', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])axios['"]/g },
|
|
26
|
+
{ category: 'network', identifier: 'got', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])got['"]/g },
|
|
27
|
+
{ category: 'network', identifier: 'node-fetch', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])node-fetch['"]/g },
|
|
28
|
+
{ category: 'network', identifier: 'XMLHttpRequest', regex: /\bnew\s+XMLHttpRequest\s*\(/g },
|
|
29
|
+
{ category: 'network', identifier: 'WebSocket', regex: /\bnew\s+WebSocket\s*\(/g },
|
|
30
|
+
{ category: 'network', identifier: 'net', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?net['"]/g },
|
|
31
|
+
{ category: 'network', identifier: 'dgram', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?dgram['"]/g },
|
|
32
|
+
{ category: 'network', identifier: 'undici', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])undici['"]/g },
|
|
33
|
+
// ── Subprocess ──
|
|
34
|
+
{ category: 'subprocess', identifier: 'child_process', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?child_process['"]/g },
|
|
35
|
+
{ category: 'subprocess', identifier: 'exec', regex: /\bexec(?:Sync|File|FileSync)?\s*\(/g },
|
|
36
|
+
{ category: 'subprocess', identifier: 'spawn', regex: /\bspawn(?:Sync)?\s*\(/g },
|
|
37
|
+
{ category: 'subprocess', identifier: 'fork', regex: /\bfork\s*\(/g },
|
|
38
|
+
{ category: 'subprocess', identifier: 'worker_threads', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?worker_threads['"]/g },
|
|
39
|
+
{ category: 'subprocess', identifier: 'cluster', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?cluster['"]/g },
|
|
40
|
+
{ category: 'subprocess', identifier: 'Deno.run', regex: /\bDeno\.run\s*\(/g },
|
|
41
|
+
{ category: 'subprocess', identifier: 'Bun.spawn', regex: /\bBun\.spawn\s*\(/g },
|
|
42
|
+
// ── Crypto ──
|
|
43
|
+
{ category: 'crypto', identifier: 'crypto', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?crypto['"]/g },
|
|
44
|
+
{ category: 'crypto', identifier: 'createSign', regex: /\bcreateSign\s*\(/g },
|
|
45
|
+
{ category: 'crypto', identifier: 'createVerify', regex: /\bcreateVerify\s*\(/g },
|
|
46
|
+
{ category: 'crypto', identifier: 'createCipher', regex: /\bcreateCipher(?:iv)?\s*\(/g },
|
|
47
|
+
{ category: 'crypto', identifier: 'createDecipher', regex: /\bcreateDecipher(?:iv)?\s*\(/g },
|
|
48
|
+
{ category: 'crypto', identifier: 'privateEncrypt', regex: /\bprivateEncrypt\s*\(/g },
|
|
49
|
+
{ category: 'crypto', identifier: 'privateDecrypt', regex: /\bprivateDecrypt\s*\(/g },
|
|
50
|
+
// ── Code Evaluation ──
|
|
51
|
+
{ category: 'codeEvaluation', identifier: 'eval', regex: /\beval\s*\(/g },
|
|
52
|
+
{ category: 'codeEvaluation', identifier: 'eval-indirect', regex: /\(\s*0\s*,\s*eval\s*\)\s*\(/g },
|
|
53
|
+
{ category: 'codeEvaluation', identifier: 'Function', regex: /\bnew\s+Function\s*\(/g },
|
|
54
|
+
{ category: 'codeEvaluation', identifier: 'vm', regex: /(?:require\s*\(\s*['"]|import\s*\(\s*['"]|from\s+['"])(?:node:)?vm['"]/g },
|
|
55
|
+
{ category: 'codeEvaluation', identifier: 'vm.runInNewContext', regex: /\brunInNewContext\s*\(/g },
|
|
56
|
+
{ category: 'codeEvaluation', identifier: 'vm.runInThisContext', regex: /\brunInThisContext\s*\(/g },
|
|
57
|
+
{ category: 'codeEvaluation', identifier: 'vm.compileFunction', regex: /\bcompileFunction\s*\(/g },
|
|
58
|
+
{ category: 'codeEvaluation', identifier: 'vm.Script', regex: /\bnew\s+vm\.Script\s*\(/g },
|
|
59
|
+
{ category: 'codeEvaluation', identifier: 'globalThis.eval', regex: /\bglobalThis\s*\.\s*eval\s*\(/g },
|
|
60
|
+
{ category: 'codeEvaluation', identifier: 'Reflect.construct-Function', regex: /\bReflect\.construct\s*\(\s*Function/g },
|
|
61
|
+
{ category: 'codeEvaluation', identifier: 'process.binding', regex: /\bprocess\.binding\s*\(/g },
|
|
62
|
+
{ category: 'codeEvaluation', identifier: 'process.dlopen', regex: /\bprocess\.dlopen\s*\(/g },
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Evasion detection heuristics.
|
|
66
|
+
*
|
|
67
|
+
* These patterns detect techniques commonly used to bypass
|
|
68
|
+
* regex-based static analysis. Unlike entitlement patterns,
|
|
69
|
+
* these flag the *mechanism* of evasion rather than a specific
|
|
70
|
+
* I/O capability.
|
|
71
|
+
*
|
|
72
|
+
* A malicious actor who knows the entitlement patterns can
|
|
73
|
+
* use `String.fromCharCode(114,101,113,117,105,114,101)` to
|
|
74
|
+
* build "require" at runtime. These heuristics catch that.
|
|
75
|
+
*/
|
|
76
|
+
const EVASION_HEURISTICS = [
|
|
77
|
+
// ── String construction ──
|
|
78
|
+
{
|
|
79
|
+
type: 'string-construction',
|
|
80
|
+
confidence: 'high',
|
|
81
|
+
regex: /\bString\.fromCharCode\s*\(/g,
|
|
82
|
+
description: 'String.fromCharCode() can build API names at runtime to evade static detection',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
type: 'string-construction',
|
|
86
|
+
confidence: 'medium',
|
|
87
|
+
regex: /\bString\.raw\s*`/g,
|
|
88
|
+
description: 'String.raw template can encode obfuscated identifiers',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: 'string-construction',
|
|
92
|
+
confidence: 'low',
|
|
93
|
+
regex: /\batob\s*\(/g,
|
|
94
|
+
description: 'atob() decodes base64 — can hide module names or code',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: 'string-construction',
|
|
98
|
+
confidence: 'low',
|
|
99
|
+
regex: /\bBuffer\.from\s*\([^)]*['"]base64['"]\s*\)/g,
|
|
100
|
+
description: 'Buffer.from(…, "base64") can decode hidden payloads',
|
|
101
|
+
},
|
|
102
|
+
// ── Indirect access ──
|
|
103
|
+
{
|
|
104
|
+
type: 'indirect-access',
|
|
105
|
+
confidence: 'high',
|
|
106
|
+
regex: /(?:globalThis|global|window|self)\s*\[\s*[^\]]*(?:\+|\()/g,
|
|
107
|
+
description: 'Computed property access on global object with dynamic expression',
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: 'indirect-access',
|
|
111
|
+
confidence: 'medium',
|
|
112
|
+
regex: /(?:globalThis|global|window|self)\s*\[\s*['"]/g,
|
|
113
|
+
description: 'Bracket-notation access on global object — bypasses dot-notation detection',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: 'indirect-access',
|
|
117
|
+
confidence: 'high',
|
|
118
|
+
regex: /\bprocess\s*\[\s*['"]/g,
|
|
119
|
+
description: 'Bracket-notation access on process object — potential binding/dlopen bypass',
|
|
120
|
+
},
|
|
121
|
+
// ── Computed import/require ──
|
|
122
|
+
{
|
|
123
|
+
type: 'computed-import',
|
|
124
|
+
confidence: 'high',
|
|
125
|
+
regex: /\brequire\s*\(\s*(?!['"])\S/g,
|
|
126
|
+
description: 'Dynamic require() with non-literal argument — module name computed at runtime',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: 'computed-import',
|
|
130
|
+
confidence: 'high',
|
|
131
|
+
regex: /\bimport\s*\(\s*(?!['"])\S/g,
|
|
132
|
+
description: 'Dynamic import() with non-literal argument — module name computed at runtime',
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
/** Minimum string length to consider for entropy analysis */
|
|
136
|
+
const ENTROPY_MIN_LENGTH = 64;
|
|
137
|
+
/** Shannon entropy threshold — values above this suggest obfuscation */
|
|
138
|
+
const ENTROPY_THRESHOLD = 5.0;
|
|
139
|
+
/** Minimum ratio of hex/unicode escapes to total characters to flag */
|
|
140
|
+
const ENCODING_DENSITY_THRESHOLD = 0.15;
|
|
141
|
+
// ============================================================================
|
|
142
|
+
// Scanner
|
|
143
|
+
// ============================================================================
|
|
144
|
+
/**
|
|
145
|
+
* Scan source text for entitlement patterns.
|
|
146
|
+
*
|
|
147
|
+
* @param source - The source code text to scan
|
|
148
|
+
* @param fileName - File name for reporting (optional)
|
|
149
|
+
* @returns All entitlement matches found
|
|
150
|
+
*/
|
|
151
|
+
export function scanSource(source, fileName) {
|
|
152
|
+
const matches = [];
|
|
153
|
+
const lines = source.split('\n');
|
|
154
|
+
const lineOffsets = buildLineOffsets(source);
|
|
155
|
+
for (const pattern of PATTERNS) {
|
|
156
|
+
// Reset regex state (global flag)
|
|
157
|
+
const regex = new RegExp(pattern.regex.source, pattern.regex.flags);
|
|
158
|
+
let match;
|
|
159
|
+
while ((match = regex.exec(source)) !== null) {
|
|
160
|
+
const lineNumber = resolveLineNumber(lineOffsets, match.index);
|
|
161
|
+
const contextLine = lines[lineNumber - 1]?.trim() ?? '';
|
|
162
|
+
matches.push({
|
|
163
|
+
category: pattern.category,
|
|
164
|
+
identifier: pattern.identifier,
|
|
165
|
+
pattern: pattern.regex.source,
|
|
166
|
+
context: contextLine,
|
|
167
|
+
line: lineNumber,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return matches;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Scan source for evasion indicators.
|
|
175
|
+
*
|
|
176
|
+
* This is a secondary analysis pass that detects patterns
|
|
177
|
+
* commonly associated with intentional static-analysis bypass.
|
|
178
|
+
* Unlike `scanSource`, which identifies specific I/O capabilities,
|
|
179
|
+
* this function flags *evasion techniques* regardless of what
|
|
180
|
+
* they ultimately execute.
|
|
181
|
+
*
|
|
182
|
+
* @param source - Source code text
|
|
183
|
+
* @returns Detected evasion indicators
|
|
184
|
+
*/
|
|
185
|
+
export function scanEvasionIndicators(source) {
|
|
186
|
+
const indicators = [];
|
|
187
|
+
const lines = source.split('\n');
|
|
188
|
+
const lineOffsets = buildLineOffsets(source);
|
|
189
|
+
// ── Pattern-based heuristics ──
|
|
190
|
+
for (const heuristic of EVASION_HEURISTICS) {
|
|
191
|
+
const regex = new RegExp(heuristic.regex.source, heuristic.regex.flags);
|
|
192
|
+
let match;
|
|
193
|
+
while ((match = regex.exec(source)) !== null) {
|
|
194
|
+
const lineNumber = resolveLineNumber(lineOffsets, match.index);
|
|
195
|
+
const contextLine = lines[lineNumber - 1]?.trim() ?? '';
|
|
196
|
+
indicators.push({
|
|
197
|
+
type: heuristic.type,
|
|
198
|
+
confidence: heuristic.confidence,
|
|
199
|
+
description: heuristic.description,
|
|
200
|
+
context: contextLine,
|
|
201
|
+
line: lineNumber,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// ── Encoding density analysis ──
|
|
206
|
+
const hexEscapes = (source.match(/\\x[0-9a-fA-F]{2}/g) ?? []).length;
|
|
207
|
+
const unicodeEscapes = (source.match(/\\u(?:[0-9a-fA-F]{4}|\{[0-9a-fA-F]+\})/g) ?? []).length;
|
|
208
|
+
const totalEscapes = hexEscapes + unicodeEscapes;
|
|
209
|
+
const density = source.length > 0 ? totalEscapes / source.length : 0;
|
|
210
|
+
if (density > ENCODING_DENSITY_THRESHOLD) {
|
|
211
|
+
indicators.push({
|
|
212
|
+
type: 'encoding-density',
|
|
213
|
+
confidence: 'high',
|
|
214
|
+
description: `High density of hex/unicode escapes (${(density * 100).toFixed(1)}%) — likely obfuscated code`,
|
|
215
|
+
context: `${totalEscapes} escape sequences in ${source.length} characters`,
|
|
216
|
+
line: 1,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// ── Entropy analysis on string literals ──
|
|
220
|
+
const stringLiteralRegex = /(?:'([^'\\]|\\.){40,}'|"([^"\\]|\\.){40,}"|`([^`\\]|\\.){40,}`)/g;
|
|
221
|
+
let strMatch;
|
|
222
|
+
while ((strMatch = stringLiteralRegex.exec(source)) !== null) {
|
|
223
|
+
const literal = strMatch[0].slice(1, -1);
|
|
224
|
+
if (literal.length >= ENTROPY_MIN_LENGTH) {
|
|
225
|
+
const entropy = computeEntropy(literal);
|
|
226
|
+
if (entropy > ENTROPY_THRESHOLD) {
|
|
227
|
+
const lineNumber = resolveLineNumber(lineOffsets, strMatch.index);
|
|
228
|
+
indicators.push({
|
|
229
|
+
type: 'entropy-anomaly',
|
|
230
|
+
confidence: 'medium',
|
|
231
|
+
description: `High-entropy string literal (Shannon entropy: ${entropy.toFixed(2)}) — possible encoded payload`,
|
|
232
|
+
context: literal.slice(0, 60) + (literal.length > 60 ? '…' : ''),
|
|
233
|
+
line: lineNumber,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return indicators;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Build `HandlerEntitlements` from detected matches.
|
|
242
|
+
*
|
|
243
|
+
* @param matches - Detected entitlement matches
|
|
244
|
+
* @returns Aggregated entitlements
|
|
245
|
+
*/
|
|
246
|
+
export function buildEntitlements(matches) {
|
|
247
|
+
const categories = new Set(matches.map(m => m.category));
|
|
248
|
+
const raw = [...new Set(matches.map(m => m.identifier))].sort();
|
|
249
|
+
return {
|
|
250
|
+
filesystem: categories.has('filesystem'),
|
|
251
|
+
network: categories.has('network'),
|
|
252
|
+
subprocess: categories.has('subprocess'),
|
|
253
|
+
crypto: categories.has('crypto'),
|
|
254
|
+
codeEvaluation: categories.has('codeEvaluation'),
|
|
255
|
+
raw,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
/** Filesystem identifiers that imply write operations */
|
|
259
|
+
const WRITE_OPS = /write|append|unlink|rmdir|mkdir|rename|copy|createWriteStream/i;
|
|
260
|
+
/** All entitlement categories for iteration */
|
|
261
|
+
const ALL_CATEGORIES = ['filesystem', 'network', 'subprocess', 'crypto', 'codeEvaluation'];
|
|
262
|
+
/** @internal */
|
|
263
|
+
const VIOLATION_RULES = [
|
|
264
|
+
// readOnly + filesystem writes → error
|
|
265
|
+
{
|
|
266
|
+
predicate: (cats, claims, allowed, matches) => !!claims.readOnly
|
|
267
|
+
&& cats.has('filesystem')
|
|
268
|
+
&& !allowed.has('filesystem')
|
|
269
|
+
&& matches.some(m => m.category === 'filesystem' && WRITE_OPS.test(m.identifier)),
|
|
270
|
+
produce: (_cats, _claims, matches) => {
|
|
271
|
+
const writeOps = matches.filter(m => m.category === 'filesystem' && WRITE_OPS.test(m.identifier));
|
|
272
|
+
const ids = writeOps.map(m => m.identifier).join(', ');
|
|
273
|
+
return {
|
|
274
|
+
category: 'filesystem',
|
|
275
|
+
declared: 'readOnly: true',
|
|
276
|
+
detected: `Filesystem write operations: ${ids}`,
|
|
277
|
+
severity: 'error',
|
|
278
|
+
description: `Tool declares readOnly but handler uses filesystem write APIs: ${ids}`,
|
|
279
|
+
};
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
// readOnly + subprocess → error
|
|
283
|
+
{
|
|
284
|
+
predicate: (cats, claims, allowed) => !!claims.readOnly && cats.has('subprocess') && !allowed.has('subprocess'),
|
|
285
|
+
produce: () => ({
|
|
286
|
+
category: 'subprocess',
|
|
287
|
+
declared: 'readOnly: true',
|
|
288
|
+
detected: 'Subprocess APIs detected',
|
|
289
|
+
severity: 'error',
|
|
290
|
+
description: 'Tool declares readOnly but handler uses subprocess APIs',
|
|
291
|
+
}),
|
|
292
|
+
},
|
|
293
|
+
// non-destructive + subprocess → warning
|
|
294
|
+
{
|
|
295
|
+
predicate: (cats, claims, allowed) => !claims.destructive && cats.has('subprocess') && !allowed.has('subprocess'),
|
|
296
|
+
produce: () => ({
|
|
297
|
+
category: 'subprocess',
|
|
298
|
+
declared: 'destructive: false',
|
|
299
|
+
detected: 'Subprocess APIs detected',
|
|
300
|
+
severity: 'warning',
|
|
301
|
+
description: 'Tool is not marked destructive but handler uses subprocess APIs — consider marking as destructive',
|
|
302
|
+
}),
|
|
303
|
+
},
|
|
304
|
+
// readOnly + network → warning
|
|
305
|
+
{
|
|
306
|
+
predicate: (cats, claims, allowed) => !!claims.readOnly && cats.has('network') && !allowed.has('network'),
|
|
307
|
+
produce: () => ({
|
|
308
|
+
category: 'network',
|
|
309
|
+
declared: 'readOnly: true',
|
|
310
|
+
detected: 'Network APIs detected',
|
|
311
|
+
severity: 'warning',
|
|
312
|
+
description: 'Tool declares readOnly but handler makes network calls — side effects possible',
|
|
313
|
+
}),
|
|
314
|
+
},
|
|
315
|
+
// codeEvaluation → always error (eval/Function can execute anything)
|
|
316
|
+
{
|
|
317
|
+
predicate: (cats, _claims, allowed) => cats.has('codeEvaluation') && !allowed.has('codeEvaluation'),
|
|
318
|
+
produce: (_cats, _claims, matches) => {
|
|
319
|
+
const evalOps = matches.filter(m => m.category === 'codeEvaluation');
|
|
320
|
+
const ids = [...new Set(evalOps.map(m => m.identifier))].join(', ');
|
|
321
|
+
return {
|
|
322
|
+
category: 'codeEvaluation',
|
|
323
|
+
declared: 'no code evaluation expected',
|
|
324
|
+
detected: `Code evaluation APIs: ${ids}`,
|
|
325
|
+
severity: 'error',
|
|
326
|
+
description: `Handler uses dynamic code evaluation (${ids}) — blast radius is unbounded; eval'd code can perform any I/O`,
|
|
327
|
+
};
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
// readOnly + codeEvaluation → error (even if allowed, flag readOnly conflict)
|
|
331
|
+
{
|
|
332
|
+
predicate: (cats, claims, allowed) => !!claims.readOnly && cats.has('codeEvaluation') && allowed.has('codeEvaluation'),
|
|
333
|
+
produce: () => ({
|
|
334
|
+
category: 'codeEvaluation',
|
|
335
|
+
declared: 'readOnly: true',
|
|
336
|
+
detected: 'Code evaluation APIs detected',
|
|
337
|
+
severity: 'error',
|
|
338
|
+
description: 'Tool declares readOnly but uses code evaluation — eval can perform writes',
|
|
339
|
+
}),
|
|
340
|
+
},
|
|
341
|
+
];
|
|
342
|
+
/**
|
|
343
|
+
* Validate detected entitlements against declared claims.
|
|
344
|
+
*
|
|
345
|
+
* Uses a rule table instead of imperative branching.
|
|
346
|
+
* Each rule encodes a policy check as pure data.
|
|
347
|
+
*
|
|
348
|
+
* @param matches - Detected matches
|
|
349
|
+
* @param claims - Declared claims from action metadata
|
|
350
|
+
* @returns Violations found
|
|
351
|
+
*/
|
|
352
|
+
export function validateClaims(matches, claims) {
|
|
353
|
+
const categories = new Set(matches.map(m => m.category));
|
|
354
|
+
const allowed = new Set(claims.allowed ?? []);
|
|
355
|
+
return VIOLATION_RULES
|
|
356
|
+
.filter(rule => rule.predicate(categories, claims, allowed, matches))
|
|
357
|
+
.map(rule => rule.produce(categories, claims, matches));
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Perform a complete entitlement scan and validation.
|
|
361
|
+
*
|
|
362
|
+
* @param source - Handler source code
|
|
363
|
+
* @param claims - Declared claims for validation
|
|
364
|
+
* @param fileName - Optional file name for reporting
|
|
365
|
+
* @returns Complete entitlement report
|
|
366
|
+
*/
|
|
367
|
+
export function scanAndValidate(source, claims = {}, fileName) {
|
|
368
|
+
const matches = scanSource(source, fileName);
|
|
369
|
+
const entitlements = buildEntitlements(matches);
|
|
370
|
+
const violations = validateClaims(matches, claims);
|
|
371
|
+
const evasionIndicators = scanEvasionIndicators(source);
|
|
372
|
+
const hasHighConfidenceEvasion = evasionIndicators.some(e => e.confidence === 'high');
|
|
373
|
+
const safe = violations.every(v => v.severity !== 'error') && !hasHighConfidenceEvasion;
|
|
374
|
+
const summary = buildSummary(entitlements, violations, evasionIndicators, safe);
|
|
375
|
+
return {
|
|
376
|
+
entitlements,
|
|
377
|
+
matches,
|
|
378
|
+
violations,
|
|
379
|
+
evasionIndicators,
|
|
380
|
+
safe,
|
|
381
|
+
summary,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
// ============================================================================
|
|
385
|
+
// Internals
|
|
386
|
+
// ============================================================================
|
|
387
|
+
/**
|
|
388
|
+
* Precompute line start offsets for O(log n) line-number resolution.
|
|
389
|
+
* @internal
|
|
390
|
+
*/
|
|
391
|
+
function buildLineOffsets(source) {
|
|
392
|
+
const offsets = [0]; // Line 1 starts at offset 0
|
|
393
|
+
for (let i = 0; i < source.length; i++) {
|
|
394
|
+
if (source[i] === '\n')
|
|
395
|
+
offsets.push(i + 1);
|
|
396
|
+
}
|
|
397
|
+
return offsets;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Binary search for the line number at a given character offset.
|
|
401
|
+
* O(log n) per lookup vs O(n) for naive iteration.
|
|
402
|
+
* @internal
|
|
403
|
+
*/
|
|
404
|
+
function resolveLineNumber(offsets, offset) {
|
|
405
|
+
let lo = 0;
|
|
406
|
+
let hi = offsets.length - 1;
|
|
407
|
+
while (lo < hi) {
|
|
408
|
+
const mid = (lo + hi + 1) >>> 1;
|
|
409
|
+
if (offsets[mid] <= offset)
|
|
410
|
+
lo = mid;
|
|
411
|
+
else
|
|
412
|
+
hi = mid - 1;
|
|
413
|
+
}
|
|
414
|
+
return lo + 1; // 1-based
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Compute Shannon entropy of a string.
|
|
418
|
+
* High entropy (> 4.5) in code regions suggests obfuscation.
|
|
419
|
+
* @internal
|
|
420
|
+
*/
|
|
421
|
+
function computeEntropy(str) {
|
|
422
|
+
if (str.length === 0)
|
|
423
|
+
return 0;
|
|
424
|
+
const freq = new Map();
|
|
425
|
+
for (const ch of str) {
|
|
426
|
+
freq.set(ch, (freq.get(ch) ?? 0) + 1);
|
|
427
|
+
}
|
|
428
|
+
let entropy = 0;
|
|
429
|
+
for (const count of freq.values()) {
|
|
430
|
+
const p = count / str.length;
|
|
431
|
+
entropy -= p * Math.log2(p);
|
|
432
|
+
}
|
|
433
|
+
return entropy;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Build a human-readable summary.
|
|
437
|
+
* @internal
|
|
438
|
+
*/
|
|
439
|
+
function buildSummary(entitlements, violations, evasionIndicators, safe) {
|
|
440
|
+
const active = ALL_CATEGORIES.filter(c => entitlements[c]);
|
|
441
|
+
const highEvasion = evasionIndicators.filter(e => e.confidence === 'high');
|
|
442
|
+
if (active.length === 0 && evasionIndicators.length === 0) {
|
|
443
|
+
return 'No I/O entitlements detected — handler is sandboxed.';
|
|
444
|
+
}
|
|
445
|
+
const parts = [];
|
|
446
|
+
if (active.length > 0) {
|
|
447
|
+
parts.push(`Entitlements: [${active.join(', ')}]`);
|
|
448
|
+
}
|
|
449
|
+
const errorCount = violations.filter(v => v.severity === 'error').length;
|
|
450
|
+
if (violations.length > 0) {
|
|
451
|
+
parts.push(`${violations.length} violation(s) (${errorCount} errors)`);
|
|
452
|
+
}
|
|
453
|
+
if (evasionIndicators.length > 0) {
|
|
454
|
+
parts.push(`${evasionIndicators.length} evasion indicator(s) (${highEvasion.length} high-confidence)`);
|
|
455
|
+
}
|
|
456
|
+
parts.push(safe ? 'SAFE' : 'UNSAFE');
|
|
457
|
+
return parts.join(' | ');
|
|
458
|
+
}
|
|
459
|
+
//# sourceMappingURL=EntitlementScanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntitlementScanner.js","sourceRoot":"","sources":["../../src/introspection/EntitlementScanner.ts"],"names":[],"mappings":"AA2JA;;;;;;GAMG;AACH,MAAM,QAAQ,GAAkC;IAC5C,mBAAmB;IACnB,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,wFAAwF,EAAE;IAC7I,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,0BAA0B,EAAE;IACjF,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,2BAA2B,EAAE;IACtF,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,4BAA4B,EAAE;IACxF,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAA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,CAAC,CAAC;IAErC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GovernanceObserver — Observability Bridge for Governance Operations
|
|
3
|
+
*
|
|
4
|
+
* Wraps governance operations (contract compilation, lockfile generation,
|
|
5
|
+
* integrity verification, attestation) with structured debug events and
|
|
6
|
+
* OpenTelemetry-compatible tracing spans.
|
|
7
|
+
*
|
|
8
|
+
* This module is the bridge between the governance/introspection layer
|
|
9
|
+
* and the observability layer. It is opt-in — governance operations
|
|
10
|
+
* work identically without it. When enabled, every governance operation
|
|
11
|
+
* emits a `GovernanceEvent` and/or a tracing span.
|
|
12
|
+
*
|
|
13
|
+
* **Zero overhead when disabled**: When no observer or tracer is
|
|
14
|
+
* configured, the wrapper functions are no-ops that delegate directly.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import type { DebugObserverFn, GovernanceOperation } from '../observability/DebugObserver.js';
|
|
19
|
+
import type { FusionTracer } from '../observability/Tracing.js';
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for governance observability.
|
|
22
|
+
*
|
|
23
|
+
* Pass to `createGovernanceObserver()` to enable debug events
|
|
24
|
+
* and/or tracing spans for governance operations.
|
|
25
|
+
*/
|
|
26
|
+
export interface GovernanceObserverConfig {
|
|
27
|
+
/** Debug event handler — receives GovernanceEvent */
|
|
28
|
+
readonly debug?: DebugObserverFn;
|
|
29
|
+
/** OpenTelemetry-compatible tracer */
|
|
30
|
+
readonly tracer?: FusionTracer;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A governance observer that emits debug events and tracing spans.
|
|
34
|
+
*
|
|
35
|
+
* All methods accept a callback that performs the actual work.
|
|
36
|
+
* The observer wraps the callback with timing and event emission.
|
|
37
|
+
*/
|
|
38
|
+
export interface GovernanceObserver {
|
|
39
|
+
/**
|
|
40
|
+
* Wrap a governance operation with observability.
|
|
41
|
+
*
|
|
42
|
+
* @param operation - Named governance operation
|
|
43
|
+
* @param label - Human-readable label
|
|
44
|
+
* @param fn - The actual work to perform
|
|
45
|
+
* @returns The result of `fn`
|
|
46
|
+
*/
|
|
47
|
+
observe<T>(operation: GovernanceOperation, label: string, fn: () => T): T;
|
|
48
|
+
/**
|
|
49
|
+
* Wrap an async governance operation with observability.
|
|
50
|
+
*
|
|
51
|
+
* @param operation - Named governance operation
|
|
52
|
+
* @param label - Human-readable label
|
|
53
|
+
* @param fn - The actual async work to perform
|
|
54
|
+
* @returns The result of `fn`
|
|
55
|
+
*/
|
|
56
|
+
observeAsync<T>(operation: GovernanceOperation, label: string, fn: () => Promise<T>): Promise<T>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Create a governance observer that emits debug events and/or tracing
|
|
60
|
+
* spans for governance operations.
|
|
61
|
+
*
|
|
62
|
+
* @param config - Observer configuration (debug handler and/or tracer)
|
|
63
|
+
* @returns A `GovernanceObserver` instance
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { createGovernanceObserver } from '@vinkius-core/mcp-fusion/introspection';
|
|
68
|
+
* import { createDebugObserver } from '@vinkius-core/mcp-fusion';
|
|
69
|
+
*
|
|
70
|
+
* const observer = createGovernanceObserver({
|
|
71
|
+
* debug: createDebugObserver(),
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* const contracts = observer.observe(
|
|
75
|
+
* 'contract.compile',
|
|
76
|
+
* 'Compiling 5 tool contracts',
|
|
77
|
+
* () => compileContracts(builders),
|
|
78
|
+
* );
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function createGovernanceObserver(config: GovernanceObserverConfig): GovernanceObserver;
|
|
82
|
+
/**
|
|
83
|
+
* Create a no-op governance observer.
|
|
84
|
+
*
|
|
85
|
+
* Used when observability is not configured. Zero overhead.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createNoopObserver(): GovernanceObserver;
|
|
88
|
+
//# sourceMappingURL=GovernanceObserver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GovernanceObserver.d.ts","sourceRoot":"","sources":["../../src/introspection/GovernanceObserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC9F,OAAO,KAAK,EAAE,YAAY,EAAwB,MAAM,6BAA6B,CAAC;AActF;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACrC,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,eAAe,CAAC;IACjC,sCAAsC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;CAClC;AAMD;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IAC/B;;;;;;;OAOG;IACH,OAAO,CAAC,CAAC,EACL,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,CAAC,GACZ,CAAC,CAAC;IAEL;;;;;;;OAOG;IACH,YAAY,CAAC,CAAC,EACV,SAAS,EAAE,mBAAmB,EAC9B,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,CAoH7F;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,kBAAkB,CAKvD"}
|