File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -301,17 +301,22 @@ if (useHttp) {
301301 // Check if request is from localhost (for same-origin requests that don't send Origin header)
302302 // Use strict matching to prevent spoofing via subdomains like "malicious-localhost.evil.com"
303303 const host = req . headers . host || ''
304- const isLocalhostHost = host === `localhost:${ port } ` ||
304+
305+ // Extract hostnames from allowedOrigins for Host header validation
306+ const allowedHosts = allowedOrigins . map ( o => new URL ( o ) . hostname )
307+
308+ const isAllowedHost = host === `localhost:${ port } ` ||
305309 host === `127.0.0.1:${ port } ` ||
306310 host === 'localhost' ||
307- host === '127.0.0.1'
311+ host === '127.0.0.1' ||
312+ allowedHosts . includes ( host )
308313
309314 // Allow requests:
310315 // 1. With Origin header from localhost (any port) or production domains
311- // 2. Without Origin header if they're from localhost (same-origin requests)
316+ // 2. Without Origin header if they're from localhost or allowed domains (same-origin requests)
312317 const isValidOrigin = origin
313318 ? ( isLocalhostOrigin ( origin ) || allowedOrigins . includes ( origin ) )
314- : isLocalhostHost
319+ : isAllowedHost
315320
316321 if ( ! isValidOrigin ) {
317322 logger . warn ( `Rejected request from invalid origin: ${ origin || 'missing' } (host: ${ host } )` )
Original file line number Diff line number Diff line change 11{
22 "name" : " @socketsecurity/mcp" ,
3- "version" : " 0.0.15 " ,
3+ "version" : " 0.0.16 " ,
44 "type" : " module" ,
55 "main" : " ./index.js" ,
66 "bin" : {
You can’t perform that action at this time.
0 commit comments