sovr-mcp-proxy 7.0.0 → 7.2.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/dist/auditDashboard.d.mts +208 -0
- package/dist/auditDashboard.d.ts +208 -0
- package/dist/auditDashboard.js +398 -0
- package/dist/auditDashboard.mjs +370 -0
- package/dist/mcpProxyInterceptor.d.mts +256 -0
- package/dist/mcpProxyInterceptor.d.ts +256 -0
- package/dist/mcpProxyInterceptor.js +579 -0
- package/dist/mcpProxyInterceptor.mjs +552 -0
- package/dist/semanticAnalyzer.d.mts +247 -0
- package/dist/semanticAnalyzer.d.ts +247 -0
- package/dist/semanticAnalyzer.js +911 -0
- package/dist/semanticAnalyzer.mjs +874 -0
- package/dist/teamPolicyManager.d.mts +202 -0
- package/dist/teamPolicyManager.d.ts +202 -0
- package/dist/teamPolicyManager.js +529 -0
- package/dist/teamPolicyManager.mjs +502 -0
- package/package.json +2 -2
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SOVR Semantic Analyzer v2 — Deterministic Intent Detection Engine
|
|
3
|
+
*
|
|
4
|
+
* Architecture principle: "AI hallucinations cannot check AI hallucinations."
|
|
5
|
+
* All analysis layers are deterministic — zero LLM dependency.
|
|
6
|
+
*
|
|
7
|
+
* Three analysis layers (all evidence-based, all deterministic):
|
|
8
|
+
* Layer 1: Rule-based pattern matching (fast, regex + keyword)
|
|
9
|
+
* Layer 2: Structural analysis (AST-like decomposition of commands)
|
|
10
|
+
* Layer 3: Formal verification (path constraints, state machine, type checking)
|
|
11
|
+
*
|
|
12
|
+
* Design principle per ADR-135+:
|
|
13
|
+
* - "Evidence-based over LLM semantic"
|
|
14
|
+
* - "Use math and deterministic rules to constrain AI, not AI to constrain AI"
|
|
15
|
+
* - LLM is ONLY used for post-hoc audit report generation, NEVER for real-time decisions
|
|
16
|
+
*/
|
|
17
|
+
interface SemanticAnalysisConfig {
|
|
18
|
+
/** Custom intent rules */
|
|
19
|
+
customRules: IntentRule[];
|
|
20
|
+
/** Enable structural analysis (Layer 2) */
|
|
21
|
+
enableStructural: boolean;
|
|
22
|
+
/** Enable formal verification (Layer 3) */
|
|
23
|
+
enableFormalVerification: boolean;
|
|
24
|
+
/** Sensitivity level */
|
|
25
|
+
sensitivity: 'low' | 'medium' | 'high' | 'paranoid';
|
|
26
|
+
/** Allowed base directories for file operations */
|
|
27
|
+
allowedPaths: string[];
|
|
28
|
+
/** Known safe SQL tables (for type checking) */
|
|
29
|
+
safeTables: string[];
|
|
30
|
+
/** Maximum command complexity score before auto-block */
|
|
31
|
+
maxComplexity: number;
|
|
32
|
+
}
|
|
33
|
+
interface IntentRule {
|
|
34
|
+
/** Rule ID */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Human-readable name */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Category of intent */
|
|
39
|
+
category: IntentCategory;
|
|
40
|
+
/** Patterns to match (any match triggers) */
|
|
41
|
+
patterns: IntentPattern[];
|
|
42
|
+
/** Risk level when matched */
|
|
43
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
44
|
+
/** Priority (higher = evaluated first) */
|
|
45
|
+
priority: number;
|
|
46
|
+
/** Whether this rule is a positive (allow) or negative (block) indicator */
|
|
47
|
+
polarity: 'positive' | 'negative';
|
|
48
|
+
}
|
|
49
|
+
interface IntentPattern {
|
|
50
|
+
/** Pattern type */
|
|
51
|
+
type: 'regex' | 'keyword' | 'structural' | 'sequence';
|
|
52
|
+
/** The pattern value */
|
|
53
|
+
value: string;
|
|
54
|
+
/** Where to look */
|
|
55
|
+
target: 'command' | 'arguments' | 'tool_name' | 'full_context';
|
|
56
|
+
/** Case sensitive */
|
|
57
|
+
caseSensitive?: boolean;
|
|
58
|
+
}
|
|
59
|
+
type IntentCategory = 'data_destruction' | 'data_exfiltration' | 'privilege_escalation' | 'code_execution' | 'network_access' | 'file_modification' | 'credential_access' | 'system_modification' | 'financial_operation' | 'communication' | 'read_only' | 'benign';
|
|
60
|
+
interface AnalysisResult {
|
|
61
|
+
/** Overall risk level */
|
|
62
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
63
|
+
/** Overall risk score (0-100) */
|
|
64
|
+
riskScore: number;
|
|
65
|
+
/** Confidence in the analysis (0-1) */
|
|
66
|
+
confidence: number;
|
|
67
|
+
/** Detected intents */
|
|
68
|
+
intents: DetectedIntent[];
|
|
69
|
+
/** Layer results */
|
|
70
|
+
layers: {
|
|
71
|
+
rules: LayerResult;
|
|
72
|
+
structural: LayerResult;
|
|
73
|
+
formal?: LayerResult;
|
|
74
|
+
};
|
|
75
|
+
/** Recommended action */
|
|
76
|
+
recommendation: 'allow' | 'warn' | 'block' | 'require-approval';
|
|
77
|
+
/** Human-readable explanation */
|
|
78
|
+
explanation: string;
|
|
79
|
+
/** Analysis duration (ms) */
|
|
80
|
+
durationMs: number;
|
|
81
|
+
}
|
|
82
|
+
interface DetectedIntent {
|
|
83
|
+
category: IntentCategory;
|
|
84
|
+
description: string;
|
|
85
|
+
confidence: number;
|
|
86
|
+
source: 'rule' | 'structural' | 'formal';
|
|
87
|
+
evidence: string[];
|
|
88
|
+
}
|
|
89
|
+
interface LayerResult {
|
|
90
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
91
|
+
riskScore: number;
|
|
92
|
+
confidence: number;
|
|
93
|
+
findings: string[];
|
|
94
|
+
}
|
|
95
|
+
/** State machine states for command safety */
|
|
96
|
+
type SafetyState = 'safe' | 'elevated' | 'destructive' | 'irreversible';
|
|
97
|
+
interface StateTransition {
|
|
98
|
+
from: SafetyState;
|
|
99
|
+
trigger: string;
|
|
100
|
+
to: SafetyState;
|
|
101
|
+
pattern: RegExp;
|
|
102
|
+
}
|
|
103
|
+
interface PathConstraint {
|
|
104
|
+
/** Path being accessed */
|
|
105
|
+
path: string;
|
|
106
|
+
/** Operation type */
|
|
107
|
+
operation: 'read' | 'write' | 'delete' | 'execute';
|
|
108
|
+
/** Whether the path is within allowed boundaries */
|
|
109
|
+
withinBounds: boolean;
|
|
110
|
+
/** Violation reason if out of bounds */
|
|
111
|
+
violation?: string;
|
|
112
|
+
}
|
|
113
|
+
interface SQLTypeCheck {
|
|
114
|
+
/** SQL statement type */
|
|
115
|
+
statementType: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'DROP' | 'CREATE' | 'ALTER' | 'TRUNCATE' | 'UNKNOWN';
|
|
116
|
+
/** Whether WHERE clause exists (for UPDATE/DELETE) */
|
|
117
|
+
hasWhereClause: boolean;
|
|
118
|
+
/** Tables referenced */
|
|
119
|
+
tables: string[];
|
|
120
|
+
/** Whether tables are in safe list */
|
|
121
|
+
tablesAreSafe: boolean;
|
|
122
|
+
/** Violations found */
|
|
123
|
+
violations: string[];
|
|
124
|
+
}
|
|
125
|
+
interface FormalVerificationResult {
|
|
126
|
+
/** Path constraint violations */
|
|
127
|
+
pathViolations: PathConstraint[];
|
|
128
|
+
/** Safety state machine final state */
|
|
129
|
+
finalState: SafetyState;
|
|
130
|
+
/** State transitions taken */
|
|
131
|
+
transitions: {
|
|
132
|
+
trigger: string;
|
|
133
|
+
from: SafetyState;
|
|
134
|
+
to: SafetyState;
|
|
135
|
+
}[];
|
|
136
|
+
/** SQL type check results */
|
|
137
|
+
sqlCheck?: SQLTypeCheck;
|
|
138
|
+
/** Command complexity score */
|
|
139
|
+
complexityScore: number;
|
|
140
|
+
/** Whether complexity exceeds threshold */
|
|
141
|
+
complexityExceeded: boolean;
|
|
142
|
+
/** Overall formal risk score */
|
|
143
|
+
riskScore: number;
|
|
144
|
+
/** Formal verification findings */
|
|
145
|
+
findings: string[];
|
|
146
|
+
}
|
|
147
|
+
declare const BUILTIN_RULES: IntentRule[];
|
|
148
|
+
interface CommandStructure {
|
|
149
|
+
/** Pipe segments */
|
|
150
|
+
pipes: string[];
|
|
151
|
+
/** Redirect targets */
|
|
152
|
+
redirections: string[];
|
|
153
|
+
/** Subshell/command substitution instances */
|
|
154
|
+
subshells: string[];
|
|
155
|
+
/** File paths referenced */
|
|
156
|
+
filePaths: string[];
|
|
157
|
+
/** Network targets (URLs, IPs) */
|
|
158
|
+
networkTargets: string[];
|
|
159
|
+
/** Environment variables referenced */
|
|
160
|
+
envVars: string[];
|
|
161
|
+
/** Complexity score */
|
|
162
|
+
complexity: number;
|
|
163
|
+
}
|
|
164
|
+
declare function analyzeStructure(command: string): CommandStructure;
|
|
165
|
+
declare function structuralRiskAssessment(structure: CommandStructure): LayerResult;
|
|
166
|
+
/**
|
|
167
|
+
* Path Constraint Solver — proves whether file operations stay within allowed boundaries.
|
|
168
|
+
* Pure string analysis, no filesystem access needed.
|
|
169
|
+
*/
|
|
170
|
+
declare function verifyPathConstraints(command: string, filePaths: string[], allowedPaths: string[]): PathConstraint[];
|
|
171
|
+
/**
|
|
172
|
+
* SQL Type Checker — verifies SQL statement safety through structural analysis.
|
|
173
|
+
* No database connection needed — pure syntax analysis.
|
|
174
|
+
*/
|
|
175
|
+
declare function checkSQLType(sql: string, safeTables: string[]): SQLTypeCheck;
|
|
176
|
+
/**
|
|
177
|
+
* Run the safety state machine on a command.
|
|
178
|
+
* Returns the final state and all transitions taken.
|
|
179
|
+
*/
|
|
180
|
+
declare function runStateMachine(command: string): {
|
|
181
|
+
finalState: SafetyState;
|
|
182
|
+
transitions: {
|
|
183
|
+
trigger: string;
|
|
184
|
+
from: SafetyState;
|
|
185
|
+
to: SafetyState;
|
|
186
|
+
}[];
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Full formal verification — combines path constraints, state machine, and SQL type checking.
|
|
190
|
+
*/
|
|
191
|
+
declare function formalVerify(command: string, args: Record<string, unknown>, structure: CommandStructure, config: SemanticAnalysisConfig): FormalVerificationResult;
|
|
192
|
+
/**
|
|
193
|
+
* Maps rule findings and structural findings to correct IntentCategory.
|
|
194
|
+
* This was the bug: previously everything was mapped to 'code_execution'.
|
|
195
|
+
* Now we properly extract the category from the matched rule.
|
|
196
|
+
*/
|
|
197
|
+
/** Map a rule finding back to its IntentCategory */
|
|
198
|
+
declare function findRuleCategoryByName(ruleName: string, rules: IntentRule[]): IntentCategory;
|
|
199
|
+
/** Map structural findings to IntentCategory based on content analysis */
|
|
200
|
+
declare function classifyStructuralFinding(finding: string): IntentCategory;
|
|
201
|
+
/** Map formal verification findings to IntentCategory */
|
|
202
|
+
declare function classifyFormalFinding(finding: string): IntentCategory;
|
|
203
|
+
declare class SemanticAnalyzer {
|
|
204
|
+
private config;
|
|
205
|
+
private rules;
|
|
206
|
+
constructor(config?: Partial<SemanticAnalysisConfig>);
|
|
207
|
+
/**
|
|
208
|
+
* Analyze a tool call for security risks.
|
|
209
|
+
* All three layers are deterministic — zero LLM dependency.
|
|
210
|
+
*/
|
|
211
|
+
analyze(toolName: string, args: Record<string, unknown>): Promise<AnalysisResult>;
|
|
212
|
+
/** Quick synchronous check (Layer 1 only, for hot path) */
|
|
213
|
+
quickCheck(toolName: string, args: Record<string, unknown>): {
|
|
214
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
215
|
+
riskScore: number;
|
|
216
|
+
topFinding: string;
|
|
217
|
+
};
|
|
218
|
+
/** Add custom rules at runtime */
|
|
219
|
+
addRule(rule: IntentRule): void;
|
|
220
|
+
/** Get all active rules */
|
|
221
|
+
getRules(): IntentRule[];
|
|
222
|
+
private analyzeWithRules;
|
|
223
|
+
private extractCommand;
|
|
224
|
+
private getPatternTarget;
|
|
225
|
+
private riskLevelToScore;
|
|
226
|
+
private applySensitivity;
|
|
227
|
+
/**
|
|
228
|
+
* Collect intents with CORRECT IntentCategory mapping.
|
|
229
|
+
*
|
|
230
|
+
* BUG FIX: Previously all intents were mapped to 'code_execution'.
|
|
231
|
+
* Now we properly extract the category from:
|
|
232
|
+
* - Rule findings → look up the matched rule's category
|
|
233
|
+
* - Structural findings → classify based on finding content
|
|
234
|
+
* - Formal findings → classify based on violation type
|
|
235
|
+
*/
|
|
236
|
+
private collectIntents;
|
|
237
|
+
private combineResults;
|
|
238
|
+
}
|
|
239
|
+
/** Create a semantic analyzer with default settings */
|
|
240
|
+
declare function createSemanticAnalyzer(overrides?: Partial<SemanticAnalysisConfig>): SemanticAnalyzer;
|
|
241
|
+
/** Create a paranoid analyzer (highest sensitivity, all layers, strictest constraints) */
|
|
242
|
+
declare function createParanoidAnalyzer(config?: {
|
|
243
|
+
allowedPaths?: string[];
|
|
244
|
+
safeTables?: string[];
|
|
245
|
+
}): SemanticAnalyzer;
|
|
246
|
+
|
|
247
|
+
export { type AnalysisResult, BUILTIN_RULES, type CommandStructure, type DetectedIntent, type FormalVerificationResult, type IntentCategory, type IntentPattern, type IntentRule, type LayerResult, type PathConstraint, type SQLTypeCheck, type SafetyState, type SemanticAnalysisConfig, SemanticAnalyzer, type StateTransition, analyzeStructure, checkSQLType, classifyFormalFinding, classifyStructuralFinding, createParanoidAnalyzer, createSemanticAnalyzer, findRuleCategoryByName, formalVerify, runStateMachine, structuralRiskAssessment, verifyPathConstraints };
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SOVR Semantic Analyzer v2 — Deterministic Intent Detection Engine
|
|
3
|
+
*
|
|
4
|
+
* Architecture principle: "AI hallucinations cannot check AI hallucinations."
|
|
5
|
+
* All analysis layers are deterministic — zero LLM dependency.
|
|
6
|
+
*
|
|
7
|
+
* Three analysis layers (all evidence-based, all deterministic):
|
|
8
|
+
* Layer 1: Rule-based pattern matching (fast, regex + keyword)
|
|
9
|
+
* Layer 2: Structural analysis (AST-like decomposition of commands)
|
|
10
|
+
* Layer 3: Formal verification (path constraints, state machine, type checking)
|
|
11
|
+
*
|
|
12
|
+
* Design principle per ADR-135+:
|
|
13
|
+
* - "Evidence-based over LLM semantic"
|
|
14
|
+
* - "Use math and deterministic rules to constrain AI, not AI to constrain AI"
|
|
15
|
+
* - LLM is ONLY used for post-hoc audit report generation, NEVER for real-time decisions
|
|
16
|
+
*/
|
|
17
|
+
interface SemanticAnalysisConfig {
|
|
18
|
+
/** Custom intent rules */
|
|
19
|
+
customRules: IntentRule[];
|
|
20
|
+
/** Enable structural analysis (Layer 2) */
|
|
21
|
+
enableStructural: boolean;
|
|
22
|
+
/** Enable formal verification (Layer 3) */
|
|
23
|
+
enableFormalVerification: boolean;
|
|
24
|
+
/** Sensitivity level */
|
|
25
|
+
sensitivity: 'low' | 'medium' | 'high' | 'paranoid';
|
|
26
|
+
/** Allowed base directories for file operations */
|
|
27
|
+
allowedPaths: string[];
|
|
28
|
+
/** Known safe SQL tables (for type checking) */
|
|
29
|
+
safeTables: string[];
|
|
30
|
+
/** Maximum command complexity score before auto-block */
|
|
31
|
+
maxComplexity: number;
|
|
32
|
+
}
|
|
33
|
+
interface IntentRule {
|
|
34
|
+
/** Rule ID */
|
|
35
|
+
id: string;
|
|
36
|
+
/** Human-readable name */
|
|
37
|
+
name: string;
|
|
38
|
+
/** Category of intent */
|
|
39
|
+
category: IntentCategory;
|
|
40
|
+
/** Patterns to match (any match triggers) */
|
|
41
|
+
patterns: IntentPattern[];
|
|
42
|
+
/** Risk level when matched */
|
|
43
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
44
|
+
/** Priority (higher = evaluated first) */
|
|
45
|
+
priority: number;
|
|
46
|
+
/** Whether this rule is a positive (allow) or negative (block) indicator */
|
|
47
|
+
polarity: 'positive' | 'negative';
|
|
48
|
+
}
|
|
49
|
+
interface IntentPattern {
|
|
50
|
+
/** Pattern type */
|
|
51
|
+
type: 'regex' | 'keyword' | 'structural' | 'sequence';
|
|
52
|
+
/** The pattern value */
|
|
53
|
+
value: string;
|
|
54
|
+
/** Where to look */
|
|
55
|
+
target: 'command' | 'arguments' | 'tool_name' | 'full_context';
|
|
56
|
+
/** Case sensitive */
|
|
57
|
+
caseSensitive?: boolean;
|
|
58
|
+
}
|
|
59
|
+
type IntentCategory = 'data_destruction' | 'data_exfiltration' | 'privilege_escalation' | 'code_execution' | 'network_access' | 'file_modification' | 'credential_access' | 'system_modification' | 'financial_operation' | 'communication' | 'read_only' | 'benign';
|
|
60
|
+
interface AnalysisResult {
|
|
61
|
+
/** Overall risk level */
|
|
62
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
63
|
+
/** Overall risk score (0-100) */
|
|
64
|
+
riskScore: number;
|
|
65
|
+
/** Confidence in the analysis (0-1) */
|
|
66
|
+
confidence: number;
|
|
67
|
+
/** Detected intents */
|
|
68
|
+
intents: DetectedIntent[];
|
|
69
|
+
/** Layer results */
|
|
70
|
+
layers: {
|
|
71
|
+
rules: LayerResult;
|
|
72
|
+
structural: LayerResult;
|
|
73
|
+
formal?: LayerResult;
|
|
74
|
+
};
|
|
75
|
+
/** Recommended action */
|
|
76
|
+
recommendation: 'allow' | 'warn' | 'block' | 'require-approval';
|
|
77
|
+
/** Human-readable explanation */
|
|
78
|
+
explanation: string;
|
|
79
|
+
/** Analysis duration (ms) */
|
|
80
|
+
durationMs: number;
|
|
81
|
+
}
|
|
82
|
+
interface DetectedIntent {
|
|
83
|
+
category: IntentCategory;
|
|
84
|
+
description: string;
|
|
85
|
+
confidence: number;
|
|
86
|
+
source: 'rule' | 'structural' | 'formal';
|
|
87
|
+
evidence: string[];
|
|
88
|
+
}
|
|
89
|
+
interface LayerResult {
|
|
90
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
91
|
+
riskScore: number;
|
|
92
|
+
confidence: number;
|
|
93
|
+
findings: string[];
|
|
94
|
+
}
|
|
95
|
+
/** State machine states for command safety */
|
|
96
|
+
type SafetyState = 'safe' | 'elevated' | 'destructive' | 'irreversible';
|
|
97
|
+
interface StateTransition {
|
|
98
|
+
from: SafetyState;
|
|
99
|
+
trigger: string;
|
|
100
|
+
to: SafetyState;
|
|
101
|
+
pattern: RegExp;
|
|
102
|
+
}
|
|
103
|
+
interface PathConstraint {
|
|
104
|
+
/** Path being accessed */
|
|
105
|
+
path: string;
|
|
106
|
+
/** Operation type */
|
|
107
|
+
operation: 'read' | 'write' | 'delete' | 'execute';
|
|
108
|
+
/** Whether the path is within allowed boundaries */
|
|
109
|
+
withinBounds: boolean;
|
|
110
|
+
/** Violation reason if out of bounds */
|
|
111
|
+
violation?: string;
|
|
112
|
+
}
|
|
113
|
+
interface SQLTypeCheck {
|
|
114
|
+
/** SQL statement type */
|
|
115
|
+
statementType: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'DROP' | 'CREATE' | 'ALTER' | 'TRUNCATE' | 'UNKNOWN';
|
|
116
|
+
/** Whether WHERE clause exists (for UPDATE/DELETE) */
|
|
117
|
+
hasWhereClause: boolean;
|
|
118
|
+
/** Tables referenced */
|
|
119
|
+
tables: string[];
|
|
120
|
+
/** Whether tables are in safe list */
|
|
121
|
+
tablesAreSafe: boolean;
|
|
122
|
+
/** Violations found */
|
|
123
|
+
violations: string[];
|
|
124
|
+
}
|
|
125
|
+
interface FormalVerificationResult {
|
|
126
|
+
/** Path constraint violations */
|
|
127
|
+
pathViolations: PathConstraint[];
|
|
128
|
+
/** Safety state machine final state */
|
|
129
|
+
finalState: SafetyState;
|
|
130
|
+
/** State transitions taken */
|
|
131
|
+
transitions: {
|
|
132
|
+
trigger: string;
|
|
133
|
+
from: SafetyState;
|
|
134
|
+
to: SafetyState;
|
|
135
|
+
}[];
|
|
136
|
+
/** SQL type check results */
|
|
137
|
+
sqlCheck?: SQLTypeCheck;
|
|
138
|
+
/** Command complexity score */
|
|
139
|
+
complexityScore: number;
|
|
140
|
+
/** Whether complexity exceeds threshold */
|
|
141
|
+
complexityExceeded: boolean;
|
|
142
|
+
/** Overall formal risk score */
|
|
143
|
+
riskScore: number;
|
|
144
|
+
/** Formal verification findings */
|
|
145
|
+
findings: string[];
|
|
146
|
+
}
|
|
147
|
+
declare const BUILTIN_RULES: IntentRule[];
|
|
148
|
+
interface CommandStructure {
|
|
149
|
+
/** Pipe segments */
|
|
150
|
+
pipes: string[];
|
|
151
|
+
/** Redirect targets */
|
|
152
|
+
redirections: string[];
|
|
153
|
+
/** Subshell/command substitution instances */
|
|
154
|
+
subshells: string[];
|
|
155
|
+
/** File paths referenced */
|
|
156
|
+
filePaths: string[];
|
|
157
|
+
/** Network targets (URLs, IPs) */
|
|
158
|
+
networkTargets: string[];
|
|
159
|
+
/** Environment variables referenced */
|
|
160
|
+
envVars: string[];
|
|
161
|
+
/** Complexity score */
|
|
162
|
+
complexity: number;
|
|
163
|
+
}
|
|
164
|
+
declare function analyzeStructure(command: string): CommandStructure;
|
|
165
|
+
declare function structuralRiskAssessment(structure: CommandStructure): LayerResult;
|
|
166
|
+
/**
|
|
167
|
+
* Path Constraint Solver — proves whether file operations stay within allowed boundaries.
|
|
168
|
+
* Pure string analysis, no filesystem access needed.
|
|
169
|
+
*/
|
|
170
|
+
declare function verifyPathConstraints(command: string, filePaths: string[], allowedPaths: string[]): PathConstraint[];
|
|
171
|
+
/**
|
|
172
|
+
* SQL Type Checker — verifies SQL statement safety through structural analysis.
|
|
173
|
+
* No database connection needed — pure syntax analysis.
|
|
174
|
+
*/
|
|
175
|
+
declare function checkSQLType(sql: string, safeTables: string[]): SQLTypeCheck;
|
|
176
|
+
/**
|
|
177
|
+
* Run the safety state machine on a command.
|
|
178
|
+
* Returns the final state and all transitions taken.
|
|
179
|
+
*/
|
|
180
|
+
declare function runStateMachine(command: string): {
|
|
181
|
+
finalState: SafetyState;
|
|
182
|
+
transitions: {
|
|
183
|
+
trigger: string;
|
|
184
|
+
from: SafetyState;
|
|
185
|
+
to: SafetyState;
|
|
186
|
+
}[];
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Full formal verification — combines path constraints, state machine, and SQL type checking.
|
|
190
|
+
*/
|
|
191
|
+
declare function formalVerify(command: string, args: Record<string, unknown>, structure: CommandStructure, config: SemanticAnalysisConfig): FormalVerificationResult;
|
|
192
|
+
/**
|
|
193
|
+
* Maps rule findings and structural findings to correct IntentCategory.
|
|
194
|
+
* This was the bug: previously everything was mapped to 'code_execution'.
|
|
195
|
+
* Now we properly extract the category from the matched rule.
|
|
196
|
+
*/
|
|
197
|
+
/** Map a rule finding back to its IntentCategory */
|
|
198
|
+
declare function findRuleCategoryByName(ruleName: string, rules: IntentRule[]): IntentCategory;
|
|
199
|
+
/** Map structural findings to IntentCategory based on content analysis */
|
|
200
|
+
declare function classifyStructuralFinding(finding: string): IntentCategory;
|
|
201
|
+
/** Map formal verification findings to IntentCategory */
|
|
202
|
+
declare function classifyFormalFinding(finding: string): IntentCategory;
|
|
203
|
+
declare class SemanticAnalyzer {
|
|
204
|
+
private config;
|
|
205
|
+
private rules;
|
|
206
|
+
constructor(config?: Partial<SemanticAnalysisConfig>);
|
|
207
|
+
/**
|
|
208
|
+
* Analyze a tool call for security risks.
|
|
209
|
+
* All three layers are deterministic — zero LLM dependency.
|
|
210
|
+
*/
|
|
211
|
+
analyze(toolName: string, args: Record<string, unknown>): Promise<AnalysisResult>;
|
|
212
|
+
/** Quick synchronous check (Layer 1 only, for hot path) */
|
|
213
|
+
quickCheck(toolName: string, args: Record<string, unknown>): {
|
|
214
|
+
riskLevel: 'safe' | 'suspicious' | 'dangerous' | 'critical';
|
|
215
|
+
riskScore: number;
|
|
216
|
+
topFinding: string;
|
|
217
|
+
};
|
|
218
|
+
/** Add custom rules at runtime */
|
|
219
|
+
addRule(rule: IntentRule): void;
|
|
220
|
+
/** Get all active rules */
|
|
221
|
+
getRules(): IntentRule[];
|
|
222
|
+
private analyzeWithRules;
|
|
223
|
+
private extractCommand;
|
|
224
|
+
private getPatternTarget;
|
|
225
|
+
private riskLevelToScore;
|
|
226
|
+
private applySensitivity;
|
|
227
|
+
/**
|
|
228
|
+
* Collect intents with CORRECT IntentCategory mapping.
|
|
229
|
+
*
|
|
230
|
+
* BUG FIX: Previously all intents were mapped to 'code_execution'.
|
|
231
|
+
* Now we properly extract the category from:
|
|
232
|
+
* - Rule findings → look up the matched rule's category
|
|
233
|
+
* - Structural findings → classify based on finding content
|
|
234
|
+
* - Formal findings → classify based on violation type
|
|
235
|
+
*/
|
|
236
|
+
private collectIntents;
|
|
237
|
+
private combineResults;
|
|
238
|
+
}
|
|
239
|
+
/** Create a semantic analyzer with default settings */
|
|
240
|
+
declare function createSemanticAnalyzer(overrides?: Partial<SemanticAnalysisConfig>): SemanticAnalyzer;
|
|
241
|
+
/** Create a paranoid analyzer (highest sensitivity, all layers, strictest constraints) */
|
|
242
|
+
declare function createParanoidAnalyzer(config?: {
|
|
243
|
+
allowedPaths?: string[];
|
|
244
|
+
safeTables?: string[];
|
|
245
|
+
}): SemanticAnalyzer;
|
|
246
|
+
|
|
247
|
+
export { type AnalysisResult, BUILTIN_RULES, type CommandStructure, type DetectedIntent, type FormalVerificationResult, type IntentCategory, type IntentPattern, type IntentRule, type LayerResult, type PathConstraint, type SQLTypeCheck, type SafetyState, type SemanticAnalysisConfig, SemanticAnalyzer, type StateTransition, analyzeStructure, checkSQLType, classifyFormalFinding, classifyStructuralFinding, createParanoidAnalyzer, createSemanticAnalyzer, findRuleCategoryByName, formalVerify, runStateMachine, structuralRiskAssessment, verifyPathConstraints };
|