@@ -2308,31 +2308,34 @@ describe('createMcpExpressApp', () => {
23082308 expect ( response . status ) . toBe ( 403 ) ;
23092309 } ) ;
23102310
2311- test ( 'should warn when binding to 0.0.0.0' , ( ) => {
2312- const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
2313- createMcpExpressApp ( { host : '0.0.0.0' } ) ;
2314- expect ( warnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '0.0.0.0' ) ) ;
2315- warnSpy . mockRestore ( ) ;
2311+ test ( 'should not apply host validation for 0.0.0.0 without allowedHosts' , async ( ) => {
2312+ const app = createMcpExpressApp ( { host : '0.0.0.0' } ) ;
2313+ app . post ( '/test' , ( _req : Request , res : Response ) => {
2314+ res . json ( { success : true } ) ;
2315+ } ) ;
2316+
2317+ // No host validation applied, so any host should be accepted
2318+ const response = await supertest ( app ) . post ( '/test' ) . set ( 'Host' , 'anything.com:3000' ) . send ( { } ) ;
2319+ expect ( response . status ) . toBe ( 200 ) ;
23162320 } ) ;
23172321
2318- test ( 'should warn when binding to :: (IPv6 all interfaces)' , ( ) => {
2319- const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
2320- createMcpExpressApp ( { host : '::' } ) ;
2321- expect ( warnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '::' ) ) ;
2322- warnSpy . mockRestore ( ) ;
2322+ test ( 'should skip host validation when skipHostHeaderValidation is true' , async ( ) => {
2323+ const app = createMcpExpressApp ( { host : '127.0.0.1' , skipHostHeaderValidation : true } ) ;
2324+ app . post ( '/test' , ( _req : Request , res : Response ) => {
2325+ res . json ( { success : true } ) ;
2326+ } ) ;
2327+
2328+ // Localhost validation would normally block this, but skipHostHeaderValidation disables it
2329+ const response = await supertest ( app ) . post ( '/test' ) . set ( 'Host' , 'evil.com:3000' ) . send ( { } ) ;
2330+ expect ( response . status ) . toBe ( 200 ) ;
23232331 } ) ;
23242332
23252333 test ( 'should use custom allowedHosts when provided' , async ( ) => {
2326- const warnSpy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
23272334 const app = createMcpExpressApp ( { host : '0.0.0.0' , allowedHosts : [ 'myapp.local' , 'localhost' ] } ) ;
23282335 app . post ( '/test' , ( _req : Request , res : Response ) => {
23292336 res . json ( { success : true } ) ;
23302337 } ) ;
23312338
2332- // Should not warn when allowedHosts is provided
2333- expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
2334- warnSpy . mockRestore ( ) ;
2335-
23362339 // Should allow myapp.local
23372340 const allowedResponse = await supertest ( app ) . post ( '/test' ) . set ( 'Host' , 'myapp.local:3000' ) . send ( { } ) ;
23382341 expect ( allowedResponse . status ) . toBe ( 200 ) ;
0 commit comments