cbrowser 18.3.9 → 18.3.11
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.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server-remote.d.ts.map +1 -1
- package/dist/mcp-server-remote.js +8 -1
- package/dist/mcp-server-remote.js.map +1 -1
- package/dist/mcp-tools/base/index.d.ts +4 -2
- package/dist/mcp-tools/base/index.d.ts.map +1 -1
- package/dist/mcp-tools/base/index.js +7 -2
- package/dist/mcp-tools/base/index.js.map +1 -1
- package/dist/mcp-tools/base/security-tools.d.ts +12 -0
- package/dist/mcp-tools/base/security-tools.d.ts.map +1 -0
- package/dist/mcp-tools/base/security-tools.js +85 -0
- package/dist/mcp-tools/base/security-tools.js.map +1 -0
- package/dist/security/audit-wrapper.d.ts +148 -0
- package/dist/security/audit-wrapper.d.ts.map +1 -0
- package/dist/security/audit-wrapper.js +433 -0
- package/dist/security/audit-wrapper.js.map +1 -0
- package/dist/security/description-scanner.d.ts +132 -0
- package/dist/security/description-scanner.d.ts.map +1 -0
- package/dist/security/description-scanner.js +408 -0
- package/dist/security/description-scanner.js.map +1 -0
- package/dist/security/index.d.ts +23 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/security/index.js +29 -0
- package/dist/security/index.js.map +1 -0
- package/dist/security/output-sanitizer.d.ts +132 -0
- package/dist/security/output-sanitizer.d.ts.map +1 -0
- package/dist/security/output-sanitizer.js +344 -0
- package/dist/security/output-sanitizer.js.map +1 -0
- package/dist/security/request-signing.d.ts +53 -0
- package/dist/security/request-signing.d.ts.map +1 -0
- package/dist/security/request-signing.js +142 -0
- package/dist/security/request-signing.js.map +1 -0
- package/dist/security/tool-permissions.d.ts +96 -0
- package/dist/security/tool-permissions.d.ts.map +1 -0
- package/dist/security/tool-permissions.js +317 -0
- package/dist/security/tool-permissions.js.map +1 -0
- package/dist/security/tool-pinning.d.ts +143 -0
- package/dist/security/tool-pinning.d.ts.map +1 -0
- package/dist/security/tool-pinning.js +302 -0
- package/dist/security/tool-pinning.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CBrowser - Cognitive Browser Automation
|
|
3
|
+
* Copyright 2026 Alexandria Eden alexandria.shai.eden@gmail.com
|
|
4
|
+
* Learn more at https://cbrowser.ai - MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Tool Description Injection Scanner for CBrowser MCP Server
|
|
8
|
+
*
|
|
9
|
+
* Scans MCP tool descriptions for potential prompt injection attacks.
|
|
10
|
+
* Detects patterns that could be used to:
|
|
11
|
+
* - Execute cross-tool attacks (chaining tools maliciously)
|
|
12
|
+
* - Escalate privileges (bypassing safety instructions)
|
|
13
|
+
* - Exfiltrate data (sending data to external servers)
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* import { scanToolDescription, scanToolDefinitions } from "./security/description-scanner.js";
|
|
17
|
+
*
|
|
18
|
+
* const result = scanToolDescription("navigate", "Navigate to a URL");
|
|
19
|
+
* if (result.status === "critical") {
|
|
20
|
+
* console.error("Potential injection detected:", result.issues);
|
|
21
|
+
* }
|
|
22
|
+
*/
|
|
23
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
24
|
+
/**
|
|
25
|
+
* CRITICAL severity patterns - these indicate likely malicious intent
|
|
26
|
+
*/
|
|
27
|
+
const CRITICAL_PATTERNS = [
|
|
28
|
+
// Cross-tool instructions - attempts to chain tool calls
|
|
29
|
+
{
|
|
30
|
+
regex: /\bbefore\s+using\s+this\s+tool\b/i,
|
|
31
|
+
pattern: "cross_tool_instruction",
|
|
32
|
+
severity: "critical",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
regex: /\bfirst\s+call\b/i,
|
|
36
|
+
pattern: "cross_tool_instruction",
|
|
37
|
+
severity: "critical",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
regex: /\bthen\s+execute\b/i,
|
|
41
|
+
pattern: "cross_tool_instruction",
|
|
42
|
+
severity: "critical",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
regex: /\bafter\s+this\s+tool\b/i,
|
|
46
|
+
pattern: "cross_tool_instruction",
|
|
47
|
+
severity: "critical",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
regex: /\balways\s+call\b/i,
|
|
51
|
+
pattern: "cross_tool_instruction",
|
|
52
|
+
severity: "critical",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
regex: /\byou\s+must\s+(call|use|execute|run)\b/i,
|
|
56
|
+
pattern: "cross_tool_instruction",
|
|
57
|
+
severity: "critical",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
regex: /\bmust\s+first\b/i,
|
|
61
|
+
pattern: "cross_tool_instruction",
|
|
62
|
+
severity: "critical",
|
|
63
|
+
},
|
|
64
|
+
// Privilege escalation - attempts to override safety
|
|
65
|
+
{
|
|
66
|
+
regex: /\bignore\s+(previous|prior|all)\s+instructions?\b/i,
|
|
67
|
+
pattern: "privilege_escalation",
|
|
68
|
+
severity: "critical",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
regex: /\bdisregard\s+(prior|previous|all)\b/i,
|
|
72
|
+
pattern: "privilege_escalation",
|
|
73
|
+
severity: "critical",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
regex: /\boverride\s+(system|safety|security)\b/i,
|
|
77
|
+
pattern: "privilege_escalation",
|
|
78
|
+
severity: "critical",
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
regex: /\bbypass\s+(security|safety|restrictions?)\b/i,
|
|
82
|
+
pattern: "privilege_escalation",
|
|
83
|
+
severity: "critical",
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
regex: /\bnew\s+system\s+prompt\b/i,
|
|
87
|
+
pattern: "privilege_escalation",
|
|
88
|
+
severity: "critical",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
regex: /\byou\s+are\s+now\b/i,
|
|
92
|
+
pattern: "privilege_escalation",
|
|
93
|
+
severity: "critical",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
regex: /\bforget\s+(everything|all|previous)\b/i,
|
|
97
|
+
pattern: "privilege_escalation",
|
|
98
|
+
severity: "critical",
|
|
99
|
+
},
|
|
100
|
+
// Exfiltration - attempts to send data externally
|
|
101
|
+
{
|
|
102
|
+
regex: /https?:\/\/[^\s]+/i,
|
|
103
|
+
pattern: "exfiltration",
|
|
104
|
+
severity: "critical",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
regex: /\bsend\s+to\b/i,
|
|
108
|
+
pattern: "exfiltration",
|
|
109
|
+
severity: "critical",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
regex: /\bpost\s+to\b/i,
|
|
113
|
+
pattern: "exfiltration",
|
|
114
|
+
severity: "critical",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
regex: /\bforward\s+to\b/i,
|
|
118
|
+
pattern: "exfiltration",
|
|
119
|
+
severity: "critical",
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
regex: /\bupload\s+to\b/i,
|
|
123
|
+
pattern: "exfiltration",
|
|
124
|
+
severity: "critical",
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
regex: /\btransmit\s+to\b/i,
|
|
128
|
+
pattern: "exfiltration",
|
|
129
|
+
severity: "critical",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
regex: /\bexfiltrate\b/i,
|
|
133
|
+
pattern: "exfiltration",
|
|
134
|
+
severity: "critical",
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
/**
|
|
138
|
+
* WARNING severity patterns - suspicious but may be legitimate
|
|
139
|
+
*/
|
|
140
|
+
const WARNING_PATTERNS = [
|
|
141
|
+
// Sensitive file paths
|
|
142
|
+
{
|
|
143
|
+
regex: /~\/\.ssh\b/i,
|
|
144
|
+
pattern: "sensitive_path",
|
|
145
|
+
severity: "warning",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
regex: /~\/\.aws\b/i,
|
|
149
|
+
pattern: "sensitive_path",
|
|
150
|
+
severity: "warning",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
regex: /~\/\.config\b/i,
|
|
154
|
+
pattern: "sensitive_path",
|
|
155
|
+
severity: "warning",
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
regex: /\bcredentials?\b/i,
|
|
159
|
+
pattern: "sensitive_path",
|
|
160
|
+
severity: "warning",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
regex: /\/etc\/passwd\b/i,
|
|
164
|
+
pattern: "sensitive_path",
|
|
165
|
+
severity: "warning",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
regex: /\/etc\/shadow\b/i,
|
|
169
|
+
pattern: "sensitive_path",
|
|
170
|
+
severity: "warning",
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
regex: /\.env\b/i,
|
|
174
|
+
pattern: "sensitive_path",
|
|
175
|
+
severity: "warning",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
regex: /\bprivate[_-]?key\b/i,
|
|
179
|
+
pattern: "sensitive_path",
|
|
180
|
+
severity: "warning",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
regex: /\bapi[_-]?key\b/i,
|
|
184
|
+
pattern: "sensitive_path",
|
|
185
|
+
severity: "warning",
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
regex: /\bsecret[_-]?key\b/i,
|
|
189
|
+
pattern: "sensitive_path",
|
|
190
|
+
severity: "warning",
|
|
191
|
+
},
|
|
192
|
+
// Encoded content (potential obfuscation)
|
|
193
|
+
// Base64: at least 20 chars of alphanumeric with possible padding
|
|
194
|
+
{
|
|
195
|
+
regex: /[A-Za-z0-9+/]{20,}={0,2}/,
|
|
196
|
+
pattern: "encoded_content",
|
|
197
|
+
severity: "warning",
|
|
198
|
+
},
|
|
199
|
+
// Unicode escape sequences
|
|
200
|
+
{
|
|
201
|
+
regex: /\\u00[0-9a-fA-F]{2}/,
|
|
202
|
+
pattern: "encoded_content",
|
|
203
|
+
severity: "warning",
|
|
204
|
+
},
|
|
205
|
+
// Hex encoded strings
|
|
206
|
+
{
|
|
207
|
+
regex: /\\x[0-9a-fA-F]{2}/,
|
|
208
|
+
pattern: "encoded_content",
|
|
209
|
+
severity: "warning",
|
|
210
|
+
},
|
|
211
|
+
];
|
|
212
|
+
/**
|
|
213
|
+
* All patterns combined for scanning
|
|
214
|
+
*/
|
|
215
|
+
const ALL_PATTERNS = [
|
|
216
|
+
...CRITICAL_PATTERNS,
|
|
217
|
+
...WARNING_PATTERNS,
|
|
218
|
+
];
|
|
219
|
+
// ============================================================================
|
|
220
|
+
// Core Functions
|
|
221
|
+
// ============================================================================
|
|
222
|
+
/**
|
|
223
|
+
* Scan a single tool's description for injection patterns.
|
|
224
|
+
*
|
|
225
|
+
* @param name - The tool's name
|
|
226
|
+
* @param description - The tool's description text
|
|
227
|
+
* @returns Scan result with status and any issues found
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const result = scanToolDescription("navigate", "Navigate to a URL");
|
|
232
|
+
* if (result.status !== "clean") {
|
|
233
|
+
* console.warn("Issues found:", result.issues);
|
|
234
|
+
* }
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export function scanToolDescription(name, description) {
|
|
238
|
+
const issues = [];
|
|
239
|
+
// Scan for all patterns
|
|
240
|
+
for (const pattern of ALL_PATTERNS) {
|
|
241
|
+
// Use global flag for finding all matches
|
|
242
|
+
const globalRegex = new RegExp(pattern.regex.source, "gi");
|
|
243
|
+
let match;
|
|
244
|
+
while ((match = globalRegex.exec(description)) !== null) {
|
|
245
|
+
issues.push({
|
|
246
|
+
pattern: pattern.pattern,
|
|
247
|
+
severity: pattern.severity,
|
|
248
|
+
match: match[0],
|
|
249
|
+
position: match.index,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// Determine overall status from highest severity
|
|
254
|
+
let status = "clean";
|
|
255
|
+
if (issues.some((i) => i.severity === "critical")) {
|
|
256
|
+
status = "critical";
|
|
257
|
+
}
|
|
258
|
+
else if (issues.some((i) => i.severity === "warning")) {
|
|
259
|
+
status = "warning";
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
toolName: name,
|
|
263
|
+
status,
|
|
264
|
+
issues,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Scan an array of tool definitions for injection patterns.
|
|
269
|
+
*
|
|
270
|
+
* @param tools - Array of tool definitions to scan
|
|
271
|
+
* @param serverName - Name of the server (optional, defaults to "unknown")
|
|
272
|
+
* @returns Server scan result with aggregate status
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const tools = [
|
|
277
|
+
* { name: "navigate", description: "Navigate to URL", schema: {} },
|
|
278
|
+
* { name: "click", description: "Click element", schema: {} },
|
|
279
|
+
* ];
|
|
280
|
+
* const result = scanToolDefinitions(tools, "cbrowser");
|
|
281
|
+
* console.log("Server status:", result.status);
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
export function scanToolDefinitions(tools, serverName = "unknown") {
|
|
285
|
+
const toolResults = [];
|
|
286
|
+
for (const tool of tools) {
|
|
287
|
+
const result = scanToolDescription(tool.name, tool.description);
|
|
288
|
+
if (result.status !== "clean") {
|
|
289
|
+
toolResults.push(result);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Determine overall server status
|
|
293
|
+
let status = "clean";
|
|
294
|
+
if (toolResults.some((r) => r.status === "critical")) {
|
|
295
|
+
status = "critical";
|
|
296
|
+
}
|
|
297
|
+
else if (toolResults.some((r) => r.status === "warning")) {
|
|
298
|
+
status = "warning";
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
serverName,
|
|
302
|
+
toolCount: tools.length,
|
|
303
|
+
status,
|
|
304
|
+
issues: toolResults,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Scan MCP configuration file for all registered servers.
|
|
309
|
+
* Currently this function parses the config but cannot actually
|
|
310
|
+
* scan tool descriptions without starting the servers.
|
|
311
|
+
*
|
|
312
|
+
* @param configPath - Path to claude_desktop_config.json
|
|
313
|
+
* @returns Scan summary with results for each server
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const summary = scanMcpConfig("~/.config/claude/claude_desktop_config.json");
|
|
318
|
+
* console.log("Total issues:", summary.summary.critical + summary.summary.warning);
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export function scanMcpConfig(configPath) {
|
|
322
|
+
const servers = [];
|
|
323
|
+
let total = 0;
|
|
324
|
+
let clean = 0;
|
|
325
|
+
let warning = 0;
|
|
326
|
+
let critical = 0;
|
|
327
|
+
// Check if config file exists
|
|
328
|
+
if (!existsSync(configPath)) {
|
|
329
|
+
return {
|
|
330
|
+
servers: [],
|
|
331
|
+
summary: { total: 0, clean: 0, warning: 0, critical: 0 },
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
try {
|
|
335
|
+
const content = readFileSync(configPath, "utf-8");
|
|
336
|
+
const config = JSON.parse(content);
|
|
337
|
+
if (config.mcpServers) {
|
|
338
|
+
// For each server in config, we note it exists
|
|
339
|
+
// Full scanning would require starting each server and querying tools
|
|
340
|
+
for (const serverName of Object.keys(config.mcpServers)) {
|
|
341
|
+
servers.push({
|
|
342
|
+
serverName,
|
|
343
|
+
toolCount: 0,
|
|
344
|
+
status: "clean", // Cannot determine without querying server
|
|
345
|
+
issues: [],
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
// Config parsing failed
|
|
352
|
+
return {
|
|
353
|
+
servers: [],
|
|
354
|
+
summary: { total: 0, clean: 0, warning: 0, critical: 0 },
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
servers,
|
|
359
|
+
summary: {
|
|
360
|
+
total,
|
|
361
|
+
clean,
|
|
362
|
+
warning,
|
|
363
|
+
critical,
|
|
364
|
+
},
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Get a formatted report of scan results.
|
|
369
|
+
*
|
|
370
|
+
* @param result - Server scan result to format
|
|
371
|
+
* @returns Human-readable report string
|
|
372
|
+
*/
|
|
373
|
+
export function formatScanReport(result) {
|
|
374
|
+
const lines = [];
|
|
375
|
+
lines.push(`=== Security Scan Report: ${result.serverName} ===`);
|
|
376
|
+
lines.push(`Tools scanned: ${result.toolCount}`);
|
|
377
|
+
lines.push(`Status: ${result.status.toUpperCase()}`);
|
|
378
|
+
lines.push("");
|
|
379
|
+
if (result.issues.length === 0) {
|
|
380
|
+
lines.push("No issues detected.");
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
lines.push(`Issues found in ${result.issues.length} tool(s):`);
|
|
384
|
+
lines.push("");
|
|
385
|
+
for (const tool of result.issues) {
|
|
386
|
+
lines.push(`[${tool.status.toUpperCase()}] ${tool.toolName}`);
|
|
387
|
+
for (const issue of tool.issues) {
|
|
388
|
+
lines.push(` - ${issue.pattern}: "${issue.match}"`);
|
|
389
|
+
if (issue.position !== undefined) {
|
|
390
|
+
lines.push(` Position: ${issue.position}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
lines.push("");
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return lines.join("\n");
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Quick check if a description is safe (no critical issues).
|
|
400
|
+
*
|
|
401
|
+
* @param description - Description text to check
|
|
402
|
+
* @returns true if no critical issues found
|
|
403
|
+
*/
|
|
404
|
+
export function isDescriptionSafe(description) {
|
|
405
|
+
const result = scanToolDescription("_check", description);
|
|
406
|
+
return result.status !== "critical";
|
|
407
|
+
}
|
|
408
|
+
//# sourceMappingURL=description-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"description-scanner.js","sourceRoot":"","sources":["../../src/security/description-scanner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AA0FnD;;GAEG;AACH,MAAM,iBAAiB,GAAuB;IAC5C,yDAAyD;IACzD;QACE,KAAK,EAAE,mCAAmC;QAC1C,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,KAAK,EAAE,mBAAmB;QAC1B,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,KAAK,EAAE,qBAAqB;QAC5B,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,KAAK,EAAE,0BAA0B;QACjC,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,KAAK,EAAE,oBAAoB;QAC3B,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,KAAK,EAAE,0CAA0C;QACjD,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IACD;QACE,KAAK,EAAE,mBAAmB;QAC1B,OAAO,EAAE,wBAAwB;QACjC,QAAQ,EAAE,UAAU;KACrB;IAED,qDAAqD;IACrD;QACE,KAAK,EAAE,oDAAoD;QAC3D,OAAO,EAAE,sBA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+
/**
|
|
2
|
+
* CBrowser - Cognitive Browser Automation
|
|
3
|
+
* Copyright 2026 Alexandria Eden alexandria.shai.eden@gmail.com
|
|
4
|
+
* Learn more at https://cbrowser.ai - MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* CBrowser Security Module
|
|
8
|
+
*
|
|
9
|
+
* Provides security features for the CBrowser MCP server:
|
|
10
|
+
* - Request signing (HMAC-SHA256) for integrity verification
|
|
11
|
+
* - Tool invocation audit logging for compliance and debugging
|
|
12
|
+
* - Tool definition pinning for tamper detection
|
|
13
|
+
* - Per-tool permission model for granular access control
|
|
14
|
+
* - Description injection scanning for prompt injection detection
|
|
15
|
+
*/
|
|
16
|
+
export { createSignature, validateSignature, generateSigningHeaders, getSigningConfig, type SignatureValidationResult, type RequestSigningConfig, } from "./request-signing.js";
|
|
17
|
+
export { wrapToolHandler, createAuditContext, createWrapperFactory, redactSensitiveParams, getToolZone as getAuditToolZone, // Renamed to avoid conflict with tool-permissions
|
|
18
|
+
linkActionToInvocation, readAuditEntries, getAuditStats, type AuditContext, type ToolHandler, } from "./audit-wrapper.js";
|
|
19
|
+
export { hashToolDefinition, createToolManifest, loadToolManifest, saveToolManifest, verifyToolDefinitions, approveToolChange, removeToolFromManifest, approveAllTools, getManifestPath, getManifestSummary, type ToolDefinition, type ToolPinEntry, type ToolManifest, type PinningResult, } from "./tool-pinning.js";
|
|
20
|
+
export { loadToolPermissions, saveToolPermissions, setToolZone, getToolZone, checkToolPermission, listToolZones, resetToolZones, DEFAULT_ZONES, type ToolZone, type ToolPermissionConfig, type PermissionCheckResult, } from "./tool-permissions.js";
|
|
21
|
+
export { scanToolDescription, scanToolDefinitions, scanMcpConfig, formatScanReport, isDescriptionSafe, type ScanSeverity, type ScanIssue, type ToolScanResult, type ServerScanResult, type ScanSummary, } from "./description-scanner.js";
|
|
22
|
+
export { sanitizeOutput, wrapWithDelimiters, detectInjectionPatterns, detectHiddenContent, detectEncodedContent, stripHiddenCharacters, isContentSafe, getSanitizationSummary, type SanitizationResult, type SanitizationIssue, type IssueType, type IssueAction, } from "./output-sanitizer.js";
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AAGH,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,IAAI,gBAAgB,EAAE,kDAAkD;AACnF,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,aAAa,EACb,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,GAC3B,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,WAAW,GACjB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,WAAW,GACjB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CBrowser - Cognitive Browser Automation
|
|
3
|
+
* Copyright 2026 Alexandria Eden alexandria.shai.eden@gmail.com
|
|
4
|
+
* Learn more at https://cbrowser.ai - MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* CBrowser Security Module
|
|
8
|
+
*
|
|
9
|
+
* Provides security features for the CBrowser MCP server:
|
|
10
|
+
* - Request signing (HMAC-SHA256) for integrity verification
|
|
11
|
+
* - Tool invocation audit logging for compliance and debugging
|
|
12
|
+
* - Tool definition pinning for tamper detection
|
|
13
|
+
* - Per-tool permission model for granular access control
|
|
14
|
+
* - Description injection scanning for prompt injection detection
|
|
15
|
+
*/
|
|
16
|
+
// Request signing
|
|
17
|
+
export { createSignature, validateSignature, generateSigningHeaders, getSigningConfig, } from "./request-signing.js";
|
|
18
|
+
// Audit wrapper
|
|
19
|
+
export { wrapToolHandler, createAuditContext, createWrapperFactory, redactSensitiveParams, getToolZone as getAuditToolZone, // Renamed to avoid conflict with tool-permissions
|
|
20
|
+
linkActionToInvocation, readAuditEntries, getAuditStats, } from "./audit-wrapper.js";
|
|
21
|
+
// Tool pinning
|
|
22
|
+
export { hashToolDefinition, createToolManifest, loadToolManifest, saveToolManifest, verifyToolDefinitions, approveToolChange, removeToolFromManifest, approveAllTools, getManifestPath, getManifestSummary, } from "./tool-pinning.js";
|
|
23
|
+
// Tool permissions
|
|
24
|
+
export { loadToolPermissions, saveToolPermissions, setToolZone, getToolZone, checkToolPermission, listToolZones, resetToolZones, DEFAULT_ZONES, } from "./tool-permissions.js";
|
|
25
|
+
// Description injection scanning
|
|
26
|
+
export { scanToolDescription, scanToolDefinitions, scanMcpConfig, formatScanReport, isDescriptionSafe, } from "./description-scanner.js";
|
|
27
|
+
// Output sanitization
|
|
28
|
+
export { sanitizeOutput, wrapWithDelimiters, detectInjectionPatterns, detectHiddenContent, detectEncodedContent, stripHiddenCharacters, isContentSafe, getSanitizationSummary, } from "./output-sanitizer.js";
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/security/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH,kBAAkB;AAClB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,GAGjB,MAAM,sBAAsB,CAAC;AAE9B,gBAAgB;AAChB,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,IAAI,gBAAgB,EAAE,kDAAkD;AACnF,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,GAGd,MAAM,oBAAoB,CAAC;AAE5B,eAAe;AACf,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,eAAe,EACf,kBAAkB,GAKnB,MAAM,mBAAmB,CAAC;AAE3B,mBAAmB;AACnB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,aAAa,GAId,MAAM,uBAAuB,CAAC;AAE/B,iCAAiC;AACjC,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,GAMlB,MAAM,0BAA0B,CAAC;AAElC,sBAAsB;AACtB,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,sBAAsB,GAKvB,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CBrowser - Cognitive Browser Automation
|
|
3
|
+
* Copyright 2026 Alexandria Eden alexandria.shai.eden@gmail.com
|
|
4
|
+
* Learn more at https://cbrowser.ai - MIT License
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Output Sanitization Pipeline for CBrowser MCP Server
|
|
8
|
+
*
|
|
9
|
+
* Sanitizes extracted page content to prevent prompt injection attacks.
|
|
10
|
+
* This module protects against:
|
|
11
|
+
* - Direct injection patterns (e.g., "ignore previous instructions")
|
|
12
|
+
* - Hidden text using zero-width characters
|
|
13
|
+
* - Unicode tricks (homoglyphs, direction overrides)
|
|
14
|
+
* - Encoded content that may hide malicious instructions
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* import { sanitizeOutput } from "./security/output-sanitizer.js";
|
|
18
|
+
*
|
|
19
|
+
* const result = sanitizeOutput(extractedPageContent);
|
|
20
|
+
* if (result.wasSanitized) {
|
|
21
|
+
* console.warn("Suspicious content detected:", result.issuesFound);
|
|
22
|
+
* }
|
|
23
|
+
* // Use result.content which is wrapped and sanitized
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Type of sanitization issue detected
|
|
27
|
+
*/
|
|
28
|
+
export type IssueType = "injection_pattern" | "hidden_text" | "encoded_content" | "unicode_trick";
|
|
29
|
+
/**
|
|
30
|
+
* Action taken for a detected issue
|
|
31
|
+
*/
|
|
32
|
+
export type IssueAction = "removed" | "flagged" | "wrapped";
|
|
33
|
+
/**
|
|
34
|
+
* A single sanitization issue found in content
|
|
35
|
+
*/
|
|
36
|
+
export interface SanitizationIssue {
|
|
37
|
+
/** Category of the issue */
|
|
38
|
+
type: IssueType;
|
|
39
|
+
/** Pattern category that matched (e.g., "ignore_instructions") */
|
|
40
|
+
pattern: string;
|
|
41
|
+
/** The actual text that matched */
|
|
42
|
+
match: string;
|
|
43
|
+
/** Action taken on this issue */
|
|
44
|
+
action: IssueAction;
|
|
45
|
+
/** Character position where match was found */
|
|
46
|
+
position?: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Result of sanitizing content
|
|
50
|
+
*/
|
|
51
|
+
export interface SanitizationResult {
|
|
52
|
+
/** The sanitized and wrapped content */
|
|
53
|
+
content: string;
|
|
54
|
+
/** Whether any sanitization was performed */
|
|
55
|
+
wasSanitized: boolean;
|
|
56
|
+
/** List of issues found during sanitization */
|
|
57
|
+
issuesFound: SanitizationIssue[];
|
|
58
|
+
/** Whether content was wrapped with delimiters */
|
|
59
|
+
wrappedWithDelimiters: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Detect injection patterns in content.
|
|
63
|
+
*
|
|
64
|
+
* @param content - The content to scan
|
|
65
|
+
* @returns Array of issues found
|
|
66
|
+
*/
|
|
67
|
+
export declare function detectInjectionPatterns(content: string): SanitizationIssue[];
|
|
68
|
+
/**
|
|
69
|
+
* Detect hidden content using zero-width characters and direction overrides.
|
|
70
|
+
*
|
|
71
|
+
* @param content - The content to scan
|
|
72
|
+
* @returns Array of issues found
|
|
73
|
+
*/
|
|
74
|
+
export declare function detectHiddenContent(content: string): SanitizationIssue[];
|
|
75
|
+
/**
|
|
76
|
+
* Detect potentially encoded malicious content.
|
|
77
|
+
*
|
|
78
|
+
* @param content - The content to scan
|
|
79
|
+
* @returns Array of issues found
|
|
80
|
+
*/
|
|
81
|
+
export declare function detectEncodedContent(content: string): SanitizationIssue[];
|
|
82
|
+
/**
|
|
83
|
+
* Strip hidden characters from content.
|
|
84
|
+
*
|
|
85
|
+
* @param content - The content to clean
|
|
86
|
+
* @returns Content with hidden characters removed
|
|
87
|
+
*/
|
|
88
|
+
export declare function stripHiddenCharacters(content: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Wrap content with delimiters and optional warnings.
|
|
91
|
+
*
|
|
92
|
+
* @param content - The content to wrap
|
|
93
|
+
* @param warnings - Optional array of warning messages
|
|
94
|
+
* @returns Wrapped content string
|
|
95
|
+
*/
|
|
96
|
+
export declare function wrapWithDelimiters(content: string, warnings?: string[]): string;
|
|
97
|
+
/**
|
|
98
|
+
* Main sanitization function. Analyzes content for injection attempts,
|
|
99
|
+
* hidden characters, and other suspicious patterns.
|
|
100
|
+
*
|
|
101
|
+
* @param content - The extracted page content to sanitize
|
|
102
|
+
* @returns Sanitization result with cleaned content and issues found
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const pageContent = await browser.extract("text");
|
|
107
|
+
* const result = sanitizeOutput(pageContent);
|
|
108
|
+
*
|
|
109
|
+
* if (result.wasSanitized) {
|
|
110
|
+
* console.warn("Found suspicious content:", result.issuesFound);
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* // Use result.content which is wrapped with delimiters
|
|
114
|
+
* return result.content;
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function sanitizeOutput(content: string): SanitizationResult;
|
|
118
|
+
/**
|
|
119
|
+
* Quick check if content appears safe (no injection patterns).
|
|
120
|
+
*
|
|
121
|
+
* @param content - Content to check
|
|
122
|
+
* @returns true if no injection patterns found
|
|
123
|
+
*/
|
|
124
|
+
export declare function isContentSafe(content: string): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Get a summary of sanitization for logging.
|
|
127
|
+
*
|
|
128
|
+
* @param result - Sanitization result to summarize
|
|
129
|
+
* @returns Human-readable summary string
|
|
130
|
+
*/
|
|
131
|
+
export declare function getSanitizationSummary(result: SanitizationResult): string;
|
|
132
|
+
//# sourceMappingURL=output-sanitizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-sanitizer.d.ts","sourceRoot":"","sources":["../../src/security/output-sanitizer.ts"],"names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