Skip to content

Commit 541fffa

Browse files
Theodor N. EngøyTheodor N. Engøy
authored andcommitted
examples: restrict elicitation CORS origin when credentials enabled
1 parent 65bbcea commit 541fffa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/server/src/elicitationUrlExample.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ const AUTH_PORT = process.env.MCP_AUTH_PORT ? Number.parseInt(process.env.MCP_AU
220220

221221
const app = createMcpExpressApp();
222222

223-
// Allow CORS all domains, expose the Mcp-Session-Id header
223+
// CORS: allow only localhost origins (typical for local dev / Inspector direct connect),
224+
// and expose the Mcp-Session-Id header.
224225
app.use(
225226
cors({
226-
origin: '*', // Allow all origins
227+
origin: [/^http:\/\/localhost(?::\d+)?$/, /^http:\/\/127\.0\.0\.1(?::\d+)?$/, /^http:\/\/\[::1\](?::\d+)?$/],
227228
exposedHeaders: ['Mcp-Session-Id'],
228-
credentials: true // Allow cookies to be sent cross-origin
229+
credentials: true
229230
})
230231
);
231232

0 commit comments

Comments
 (0)