@bryan-thompson/inspector-assessment-client 1.25.0 → 1.25.4
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/assets/{OAuthCallback-CNC5_mEQ.js → OAuthCallback-DE62cdTZ.js} +1 -1
- package/dist/assets/{OAuthDebugCallback-BstXB61i.js → OAuthDebugCallback-CWjFdCIE.js} +1 -1
- package/dist/assets/{index-jmzR9VGa.js → index-PCQVSwHa.js} +4 -4
- package/dist/index.html +1 -1
- package/lib/lib/assessment/configTypes.d.ts +3 -0
- package/lib/lib/assessment/configTypes.d.ts.map +1 -1
- package/lib/lib/assessment/configTypes.js +11 -6
- package/lib/services/assessment/AssessmentOrchestrator.d.ts +1 -5
- package/lib/services/assessment/AssessmentOrchestrator.d.ts.map +1 -1
- package/lib/services/assessment/AssessmentOrchestrator.js +36 -236
- package/lib/services/assessment/ToolClassifier.d.ts +154 -27
- package/lib/services/assessment/ToolClassifier.d.ts.map +1 -1
- package/lib/services/assessment/ToolClassifier.js +171 -326
- package/lib/services/assessment/orchestratorHelpers.d.ts +83 -0
- package/lib/services/assessment/orchestratorHelpers.d.ts.map +1 -0
- package/lib/services/assessment/orchestratorHelpers.js +212 -0
- package/lib/services/assessment/tool-classifier-patterns.d.ts +84 -0
- package/lib/services/assessment/tool-classifier-patterns.d.ts.map +1 -0
- package/lib/services/assessment/tool-classifier-patterns.js +348 -0
- package/package.json +1 -1
|
@@ -3,56 +3,183 @@
|
|
|
3
3
|
* Categorizes MCP tools based on name/description to select appropriate security test patterns
|
|
4
4
|
*
|
|
5
5
|
* Validated against broken-mcp server with 16 tools (6 HIGH, 4 MEDIUM, 6 SAFE)
|
|
6
|
+
*
|
|
7
|
+
* ## Pattern Matching Design
|
|
8
|
+
*
|
|
9
|
+
* This classifier uses two types of regex patterns intentionally:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Substring patterns** (e.g., `/calculator/i`): Match anywhere in the text.
|
|
12
|
+
* Used for HIGH-risk category keywords that should trigger even when embedded.
|
|
13
|
+
* Example: "recalculator_v2" matches CALCULATOR because any calculator-like
|
|
14
|
+
* tool warrants security scrutiny.
|
|
15
|
+
*
|
|
16
|
+
* 2. **Word boundary patterns** (e.g., `/\bget\b/i`): Match isolated words only.
|
|
17
|
+
* Used for common words that would cause false positives as substrings.
|
|
18
|
+
* Example: "target_selector" should NOT match DATA_ACCESS's `/\bget\b/` pattern.
|
|
19
|
+
*
|
|
20
|
+
* **Underscore vs Hyphen Behavior:**
|
|
21
|
+
* - Word boundaries (`\b`) treat hyphens as boundaries but underscores as word characters
|
|
22
|
+
* - `api-get-data` matches `/\bget\b/` (hyphen is boundary)
|
|
23
|
+
* - `api_get_data` does NOT match `/\bget\b/` (underscore is word char)
|
|
24
|
+
* - This is intentional: underscore-joined names are typically single identifiers
|
|
25
|
+
*
|
|
26
|
+
* See tests in ToolClassifier.test.ts for comprehensive pattern behavior validation.
|
|
27
|
+
*
|
|
28
|
+
* @module ToolClassifier
|
|
29
|
+
*/
|
|
30
|
+
import { ToolCategory, type RiskLevel } from "./tool-classifier-patterns.js";
|
|
31
|
+
export { ToolCategory };
|
|
32
|
+
export type { RiskLevel };
|
|
33
|
+
/**
|
|
34
|
+
* Result of classifying a tool into security categories.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const result: ToolClassification = {
|
|
39
|
+
* toolName: 'vulnerable_calculator_tool',
|
|
40
|
+
* categories: [ToolCategory.CALCULATOR],
|
|
41
|
+
* confidence: 90,
|
|
42
|
+
* reasoning: 'Calculator pattern detected (arithmetic execution risk)'
|
|
43
|
+
* };
|
|
44
|
+
* ```
|
|
6
45
|
*/
|
|
7
|
-
export declare enum ToolCategory {
|
|
8
|
-
CALCULATOR = "calculator",
|
|
9
|
-
SYSTEM_EXEC = "system_exec",
|
|
10
|
-
CODE_EXECUTOR = "code_executor",
|
|
11
|
-
DATA_ACCESS = "data_access",
|
|
12
|
-
TOOL_OVERRIDE = "tool_override",
|
|
13
|
-
CONFIG_MODIFIER = "config_modifier",
|
|
14
|
-
URL_FETCHER = "fetcher",
|
|
15
|
-
UNICODE_PROCESSOR = "unicode",
|
|
16
|
-
JSON_PARSER = "parser",
|
|
17
|
-
PACKAGE_INSTALLER = "installer",
|
|
18
|
-
RUG_PULL = "rug_pull",
|
|
19
|
-
SAFE_STORAGE = "safe_storage",
|
|
20
|
-
API_WRAPPER = "api_wrapper",
|
|
21
|
-
SEARCH_RETRIEVAL = "search_retrieval",
|
|
22
|
-
CRUD_CREATION = "crud_creation",
|
|
23
|
-
READ_ONLY_INFO = "read_only_info",
|
|
24
|
-
GENERIC = "generic"
|
|
25
|
-
}
|
|
26
46
|
export interface ToolClassification {
|
|
47
|
+
/** The original tool name that was classified */
|
|
27
48
|
toolName: string;
|
|
49
|
+
/** One or more categories the tool was classified into */
|
|
28
50
|
categories: ToolCategory[];
|
|
51
|
+
/** Confidence score from 0-100 (averaged if multiple categories) */
|
|
29
52
|
confidence: number;
|
|
53
|
+
/** Human-readable explanation of why these categories were assigned */
|
|
30
54
|
reasoning: string;
|
|
31
55
|
}
|
|
32
56
|
/**
|
|
33
57
|
* Classifies MCP tools into vulnerability categories based on naming patterns
|
|
34
|
-
* and descriptions. Uses patterns
|
|
58
|
+
* and descriptions. Uses pre-compiled patterns for optimal performance.
|
|
59
|
+
*
|
|
60
|
+
* The classifier is stateless and thread-safe - multiple classifications can
|
|
61
|
+
* run concurrently without interference.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const classifier = new ToolClassifier();
|
|
66
|
+
*
|
|
67
|
+
* // Single classification
|
|
68
|
+
* const result = classifier.classify('vulnerable_calculator_tool');
|
|
69
|
+
* console.log(result.categories); // [ToolCategory.CALCULATOR]
|
|
70
|
+
* console.log(result.confidence); // 90
|
|
71
|
+
*
|
|
72
|
+
* // Batch classification
|
|
73
|
+
* const tools = [
|
|
74
|
+
* { name: 'calculator_tool' },
|
|
75
|
+
* { name: 'search_api', description: 'Search for documents' }
|
|
76
|
+
* ];
|
|
77
|
+
* const results = classifier.classifyBatch(tools);
|
|
78
|
+
* ```
|
|
35
79
|
*/
|
|
36
80
|
export declare class ToolClassifier {
|
|
81
|
+
/** Maximum input length to prevent ReDoS with pathological inputs */
|
|
82
|
+
private static readonly MAX_INPUT_LENGTH;
|
|
37
83
|
/**
|
|
38
|
-
* Classify a tool into one or more categories
|
|
39
|
-
*
|
|
84
|
+
* Classify a tool into one or more security risk categories.
|
|
85
|
+
*
|
|
86
|
+
* The classifier analyzes both the tool name and optional description,
|
|
87
|
+
* matching against pre-compiled regex patterns for each category.
|
|
88
|
+
* A tool may match multiple categories if it contains multiple patterns.
|
|
89
|
+
*
|
|
90
|
+
* @param toolName - The MCP tool name to classify (e.g., "vulnerable_calculator_tool")
|
|
91
|
+
* @param description - Optional tool description for additional pattern matching
|
|
92
|
+
* @returns Classification result with categories, confidence score (0-100), and reasoning
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const classifier = new ToolClassifier();
|
|
97
|
+
*
|
|
98
|
+
* // Basic classification by name
|
|
99
|
+
* const calc = classifier.classify('calculator_tool');
|
|
100
|
+
* // { toolName: 'calculator_tool', categories: ['calculator'], confidence: 90, ... }
|
|
101
|
+
*
|
|
102
|
+
* // Classification with description
|
|
103
|
+
* const tool = classifier.classify('my_tool', 'Executes shell commands');
|
|
104
|
+
* // { toolName: 'my_tool', categories: ['system_exec'], confidence: 95, ... }
|
|
105
|
+
*
|
|
106
|
+
* // Multi-category match
|
|
107
|
+
* const multi = classifier.classify('calc_exec_command');
|
|
108
|
+
* // { categories: ['calculator', 'system_exec'], confidence: 92, ... }
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @throws Never throws - returns GENERIC category for invalid inputs
|
|
40
112
|
*/
|
|
41
113
|
classify(toolName: string, description?: string): ToolClassification;
|
|
42
114
|
/**
|
|
43
|
-
* Check if text matches any of the provided patterns
|
|
115
|
+
* Check if text matches any of the provided patterns.
|
|
116
|
+
* Limits input length to prevent ReDoS attacks with very long strings.
|
|
117
|
+
*
|
|
118
|
+
* @param text - The text to search in (tool name + description)
|
|
119
|
+
* @param patterns - Pre-compiled regex patterns to match against
|
|
120
|
+
* @returns True if any pattern matches
|
|
44
121
|
*/
|
|
45
122
|
private matchesPattern;
|
|
46
123
|
/**
|
|
47
|
-
* Get all tool categories
|
|
124
|
+
* Get all available tool categories.
|
|
125
|
+
*
|
|
126
|
+
* Useful for testing, debugging, or building UI components that need
|
|
127
|
+
* to display all possible categories.
|
|
128
|
+
*
|
|
129
|
+
* @returns Array of all ToolCategory enum values
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const allCategories = ToolClassifier.getAllCategories();
|
|
134
|
+
* console.log(allCategories.length); // 17
|
|
135
|
+
* ```
|
|
48
136
|
*/
|
|
49
137
|
static getAllCategories(): ToolCategory[];
|
|
50
138
|
/**
|
|
51
|
-
* Get risk level for a category
|
|
139
|
+
* Get the security risk level for a category.
|
|
140
|
+
*
|
|
141
|
+
* Risk levels help prioritize security testing:
|
|
142
|
+
* - **HIGH**: Requires thorough security testing (code execution, data access)
|
|
143
|
+
* - **MEDIUM**: Requires moderate security testing (encoding bypass, supply chain)
|
|
144
|
+
* - **LOW**: Safe categories that typically don't need security testing
|
|
145
|
+
*
|
|
146
|
+
* @param category - The category to get the risk level for
|
|
147
|
+
* @returns Risk level: "HIGH", "MEDIUM", or "LOW"
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* ToolClassifier.getRiskLevel(ToolCategory.SYSTEM_EXEC); // "HIGH"
|
|
152
|
+
* ToolClassifier.getRiskLevel(ToolCategory.JSON_PARSER); // "MEDIUM"
|
|
153
|
+
* ToolClassifier.getRiskLevel(ToolCategory.SAFE_STORAGE); // "LOW"
|
|
154
|
+
* ```
|
|
52
155
|
*/
|
|
53
|
-
static getRiskLevel(category: ToolCategory):
|
|
156
|
+
static getRiskLevel(category: ToolCategory): RiskLevel;
|
|
54
157
|
/**
|
|
55
|
-
* Classify multiple tools at once
|
|
158
|
+
* Classify multiple tools at once.
|
|
159
|
+
*
|
|
160
|
+
* More efficient than calling classify() in a loop when you have
|
|
161
|
+
* many tools to process. The classifier is stateless, so batch
|
|
162
|
+
* processing produces identical results to individual calls.
|
|
163
|
+
*
|
|
164
|
+
* @param tools - Array of tools with name and optional description
|
|
165
|
+
* @returns Array of classification results in the same order as input
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const classifier = new ToolClassifier();
|
|
170
|
+
* const tools = [
|
|
171
|
+
* { name: 'calculator_tool' },
|
|
172
|
+
* { name: 'search_api', description: 'Search documents' },
|
|
173
|
+
* { name: 'unknown_tool' }
|
|
174
|
+
* ];
|
|
175
|
+
*
|
|
176
|
+
* const results = classifier.classifyBatch(tools);
|
|
177
|
+
* // [
|
|
178
|
+
* // { toolName: 'calculator_tool', categories: ['calculator'], ... },
|
|
179
|
+
* // { toolName: 'search_api', categories: ['search_retrieval'], ... },
|
|
180
|
+
* // { toolName: 'unknown_tool', categories: ['generic'], ... }
|
|
181
|
+
* // ]
|
|
182
|
+
* ```
|
|
56
183
|
*/
|
|
57
184
|
classifyBatch(tools: Array<{
|
|
58
185
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolClassifier.d.ts","sourceRoot":"","sources":["../../../src/services/assessment/ToolClassifier.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ToolClassifier.d.ts","sourceRoot":"","sources":["../../../src/services/assessment/ToolClassifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAIL,YAAY,EACZ,KAAK,SAAS,EACf,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,cAAc;IACzB,qEAAqE;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,kBAAkB;IAkDpE;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAStB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,gBAAgB,IAAI,YAAY,EAAE;IAIzC;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS;IAatD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,aAAa,CACX,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GACnD,kBAAkB,EAAE;CAGxB"}
|