Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.2] - 2026-11-22

### Security
- Limit the Next.js log route to development and keep automatic MCP forwarding on validated loopback targets without redirects.
- Validate Host and Origin across the MCP HTTP listeners and remove permissive CORS.
- Update dependencies to address known advisories.

## [1.1.0] - 2025-09-22

### Added
Expand Down
4 changes: 2 additions & 2 deletions example/next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"lint": "next lint"
},
"dependencies": {
"next": "15.5.28",
"next": "15.5.29",
"react": "19.1.1",
"react-dom": "19.1.1"
},
"devDependencies": {
"@browser-echo/mcp": "1.1.0",
"@browser-echo/mcp": "workspace:*",
"@browser-echo/next": "1.1.0",
"@eslint/eslintrc": "3.3.5",
"@tailwindcss/postcss": "4.3.0",
Expand Down
4 changes: 2 additions & 2 deletions example/nuxt-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"postinstall": "nuxt prepare"
},
"dependencies": {
"nuxt": "4.5.1",
"vue": "3.5.34",
"nuxt": "4.6.4",
"vue": "3.5.45",
"vue-router": "4.6.4"
},
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac",
Expand Down
2 changes: 1 addition & 1 deletion example/react-vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"eslint-plugin-react-refresh": "0.4.26",
"globals": "16.5.0",
"typescript": "5.9.3",
"vite": "7.3.3"
"vite": "7.3.8"
}
}
4 changes: 2 additions & 2 deletions example/vue-vite-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "3.5.34"
"vue": "3.5.45"
},
"devDependencies": {
"@browser-echo/vite": "1.1.0",
"@vitejs/plugin-vue": "6.0.6",
"typescript": "5.9.3",
"vite": "7.3.3",
"vite": "7.3.8",
"vue-tsc": "3.2.8"
}
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
"@types/node": "24.12.4",
"eslint": "9.39.4",
"jsdom": "26.1.0",
"tsx": "4.21.0",
"tsx": "4.23.4",
"typescript": "5.9.3",
"unbuild": "3.6.1",
"vitest": "3.2.6"
"vitest": "4.1.12"
},
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac",
"dependencies": {
"glob": "11.1.0"
"glob": "14.0.6"
},
"pnpm": {
"overrides": {
"@typescript-eslint/typescript-estree@8.59.3>minimatch": "11.0.8",
"@vue/language-core@2.2.12>minimatch": "11.0.8",
"mkdist>esbuild": "0.25.12",
"next>postcss": "8.5.14",
"next>postcss": "8.5.33",
"readdir-glob@3.0.0>minimatch": "11.0.8",
"unbuild>esbuild": "0.25.12"
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@browser-echo/core",
"version": "1.1.1",
"version": "1.1.2",
"type": "module",
"sideEffects": false,
"repository": {
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export function hasExplicitMcpUrl(value = process.env.BROWSER_ECHO_MCP_URL): boo
return Boolean(normalized && !['undefined', 'null', 'false', '0'].includes(normalized));
}

export function resolveBrowserEchoMcpTarget(cwd = process.cwd()): BrowserEchoMcpTarget | null {
export function resolveBrowserEchoMcpTarget(
cwd = process.cwd(),
{ searchParents = true }: { searchParents?: boolean } = {},
): BrowserEchoMcpTarget | null {
try {
let dir = cwd;
for (let depth = 0; depth < 10; depth++) {
Expand All @@ -28,10 +31,11 @@ export function resolveBrowserEchoMcpTarget(cwd = process.cwd()): BrowserEchoMcp

return {
url,
routeLogs: normalizeMcpRoute(data?.route ?? data?.routeLogs),
routeLogs: normalizeMcpRoute(data?.route ?? data?.routeLogs, url),
};
}

if (!searchParents) break;
const parent = dirname(dir);
if (parent === dir) break;
dir = parent;
Expand All @@ -54,7 +58,7 @@ export async function forwardBrowserEchoPayload(
const target = resolveBrowserEchoMcpTarget(options.cwd);
if (!target) return false;

return forwardToBrowserEchoMcp(target, payload, options);
return forwardToBrowserEchoMcp(target, payload, { ...options, redirect: 'error' });
}

export async function forwardToBrowserEchoMcp(
Expand All @@ -63,6 +67,7 @@ export async function forwardToBrowserEchoMcp(
options: {
fetchImpl?: typeof fetch;
timeoutMs?: number;
redirect?: RequestRedirect;
} = {},
): Promise<boolean> {
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
Expand All @@ -75,6 +80,7 @@ export async function forwardToBrowserEchoMcp(
headers: { 'content-type': 'application/json' },
body: JSON.stringify(payload),
cache: 'no-store' as RequestCache,
redirect: options.redirect,
};
const timeout = createTimeoutSignal(timeoutMs);

Expand All @@ -99,7 +105,7 @@ function normalizeLocalMcpUrl(value: unknown): string {
try {
const parsed = new URL(raw);
if (parsed.protocol !== 'http:') return '';
if (!LOCAL_MCP_HOSTS.has(parsed.hostname)) return '';
if (!LOCAL_MCP_HOSTS.has(parsed.hostname) || parsed.username || parsed.password) return '';

const path = parsed.pathname.replace(/\/+$/g, '');
if (path && path !== '/mcp') return '';
Expand All @@ -113,11 +119,13 @@ function normalizeLocalMcpUrl(value: unknown): string {
}
}

function normalizeMcpRoute(value: unknown): `/${string}` {
function normalizeMcpRoute(value: unknown, origin: string): `/${string}` {
if (typeof value !== 'string') return '/__client-logs';
const route = value.trim();
if (!route.startsWith('/') || route.startsWith('//') || route.includes('://')) return '/__client-logs';
return route as `/${string}`;
const parsed = new URL(route, origin);
if (parsed.origin !== origin || parsed.pathname.startsWith('//')) return '/__client-logs';
return (parsed.pathname + parsed.search) as `/${string}`;
}

function createTimeoutSignal(timeoutMs: number): { signal: AbortSignal; clear: () => void } {
Expand Down
36 changes: 30 additions & 6 deletions packages/core/test/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { resolveBrowserEchoMcpTarget } from '../src/server';
import { describe, expect, it, vi } from 'vitest';
import { forwardBrowserEchoPayload, resolveBrowserEchoMcpTarget } from '../src/server';

describe('server MCP discovery', () => {
it('normalizes local MCP URLs and legacy routeLogs', () => {
Expand All @@ -22,11 +22,16 @@ describe('server MCP discovery', () => {
}
});

it('rejects non-local URLs', () => {
it.each([
'https://example.test/mcp',
'http://localhost.example.test/mcp',
'http://127.0.0.1.example.test/mcp',
'http://user@localhost/mcp',
])('rejects an invalid discovery URL (%s)', (url) => {
const dir = mkdtempSync(join(tmpdir(), 'be-core-remote-'));
try {
writeFileSync(join(dir, '.browser-echo-mcp.json'), JSON.stringify({
url: 'https://example.com/mcp',
url,
route: '/__client-logs',
}));

Expand All @@ -36,17 +41,36 @@ describe('server MCP discovery', () => {
}
});

it('defaults unsafe routes to the log endpoint', () => {
it.each([
'//example.test/path',
String.raw`/\example.test/path`,
])('defaults unsafe routes to the log endpoint (%s)', (route) => {
const dir = mkdtempSync(join(tmpdir(), 'be-core-route-'));
try {
writeFileSync(join(dir, '.browser-echo-mcp.json'), JSON.stringify({
url: 'http://127.0.0.1:5179',
route: '//evil.test/path',
route,
}));

expect(resolveBrowserEchoMcpTarget(dir)?.routeLogs).toBe('/__client-logs');
} finally {
rmSync(dir, { recursive: true, force: true });
}
});

it('blocks redirects in automatic forwarding even without a compatible abort signal', async () => {
const dir = mkdtempSync(join(tmpdir(), 'be-core-redirect-'));
try {
writeFileSync(join(dir, '.browser-echo-mcp.json'), JSON.stringify({ url: 'http://localhost:5179' }));
const fetchImpl = vi.fn<typeof fetch>()
.mockRejectedValueOnce(new TypeError('Incompatible AbortSignal'))
.mockResolvedValueOnce({ ok: false } as Response);

expect(await forwardBrowserEchoPayload({}, { cwd: dir, fetchImpl })).toBe(false);
expect(fetchImpl).toHaveBeenCalledTimes(2);
for (const [, init] of fetchImpl.mock.calls) expect(init?.redirect).toBe('error');
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});
8 changes: 6 additions & 2 deletions packages/mcp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ In HTTP mode:
- Full **Streamable HTTP** MCP endpoint and HTTP ingest endpoint run on the specified host/port
- Console output: `MCP (Streamable HTTP) listening → http://127.0.0.1:<port>/mcp`

Both HTTP listeners validate the Host against the bound address and port. Loopback binds accept local aliases, and wildcard binds accept the concrete destination IP and local aliases. Requests with an Origin must match the HTTP address used for the request. Native clients can omit Origin.

An explicit LAN or wildcard bind exposes the listener to reachable peers. These checks do not authenticate clients.

### Custom Configuration

```bash
Expand All @@ -334,10 +338,10 @@ node packages/mcp/bin/cli.mjs --http --host 0.0.0.0 --port 5179

### Browser → Ingest (Recommended)

Your framework packages automatically send logs to the ingest endpoint:
Browser logs go to your framework's development route on the app origin. The framework forwards the payload to the MCP ingest endpoint:

```typescript
// Browser automatically POSTs to ingest endpoint
// Framework server forwards to the MCP ingest endpoint
POST http://127.0.0.1:5179/__client-logs
{
"sessionId": "tab-123",
Expand Down
6 changes: 3 additions & 3 deletions packages/mcp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@browser-echo/mcp",
"version": "1.1.1",
"version": "1.1.2",
"private": false,
"type": "module",
"main": "dist/index.mjs",
Expand All @@ -25,10 +25,10 @@
"express": "^4 || ^5"
},
"dependencies": {
"@modelcontextprotocol/sdk": "1.26.0",
"@modelcontextprotocol/sdk": "1.32.2",
"citty": "0.1.6",
"h3": "1.15.9",
"zod": "4.4.3"
"zod": "4.6.6"
},
"devDependencies": {
"typescript": "5.9.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function startMcpServer(options: {

// Start Streamable HTTP transport on specified or default host/port
const host = options.host || '127.0.0.1';
const port = options.port || 5179;
const port = options.port ?? 5179;
const endpoint = options.endpoint || '/mcp';
const logsRoute = options.logsRoute || '/__client-logs';
await startHttpServer(mcp, store, { host, port, endpoint, logsRoute });
Expand Down
Loading
Loading