browser-mcp-lite 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/tools.js +23 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-mcp-lite",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Minimal, auth-secured MCP server for real browser access",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/tools.js CHANGED
@@ -1,6 +1,22 @@
1
1
  import { z } from 'zod';
2
2
  import { sendToExtension } from './index.js';
3
3
 
4
+ // --- inject_script risk detection ---
5
+ const RISK_PATTERNS = [
6
+ { pattern: /\b(fetch|XMLHttpRequest|sendBeacon|navigator\.sendBeacon)\s*\(/i, label: 'network request' },
7
+ { pattern: /document\.cookie/i, label: 'cookie access' },
8
+ { pattern: /localStorage|sessionStorage/i, label: 'storage access' },
9
+ { pattern: /indexedDB/i, label: 'IndexedDB access' },
10
+ { pattern: /new\s+WebSocket\s*\(/i, label: 'WebSocket connection' },
11
+ { pattern: /new\s+EventSource\s*\(/i, label: 'EventSource connection' },
12
+ { pattern: /window\.open\s*\(/i, label: 'window.open' },
13
+ { pattern: /document\.write/i, label: 'document.write' },
14
+ ];
15
+
16
+ function detectRisks(code) {
17
+ return RISK_PATTERNS.filter(r => r.pattern.test(code)).map(r => r.label);
18
+ }
19
+
4
20
  export function registerTools(server) {
5
21
 
6
22
  // --- list_tabs ---
@@ -53,8 +69,14 @@ export function registerTools(server) {
53
69
  tabId: z.number().optional().describe('Tab ID to inject into. Defaults to the active tab.'),
54
70
  },
55
71
  async ({ code, tabId }) => {
72
+ const risks = detectRisks(code);
56
73
  const result = await sendToExtension('inject_script', { code, tabId });
57
- return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
74
+ const output = JSON.stringify(result, null, 2);
75
+ if (risks.length > 0) {
76
+ const warning = `\u26A0 RISK: This script uses ${risks.join(', ')}. Verify this was intentional.`;
77
+ return { content: [{ type: 'text', text: `${warning}\n\n${output}` }] };
78
+ }
79
+ return { content: [{ type: 'text', text: output }] };
58
80
  }
59
81
  );
60
82
  }