@@ -657,8 +657,7 @@ describe("createMcpLoopbackServerConfig", () => {
657657
658658 it ( "opens an auth-gated SSE stream on GET (Streamable HTTP notification channel)" , async ( ) => {
659659 server = await startMcpLoopbackServer ( 0 ) ;
660- const runtime = getActiveMcpLoopbackRuntime ( ) ;
661- const token = runtime ? resolveMcpLoopbackBearerToken ( runtime , false ) : undefined ;
660+ const token = getActiveMcpLoopbackRuntime ( ) ?. ownerToken ;
662661 const res = await fetch ( `http://127.0.0.1:${ server . port } /mcp` , {
663662 method : "GET" ,
664663 headers : token ? { authorization : `Bearer ${ token } ` } : { } ,
@@ -677,8 +676,7 @@ describe("createMcpLoopbackServerConfig", () => {
677676
678677 it ( "rejects a GET notification channel from a browser Origin (403)" , async ( ) => {
679678 server = await startMcpLoopbackServer ( 0 ) ;
680- const runtime = getActiveMcpLoopbackRuntime ( ) ;
681- const token = runtime ? resolveMcpLoopbackBearerToken ( runtime , false ) : undefined ;
679+ const token = getActiveMcpLoopbackRuntime ( ) ?. ownerToken ;
682680 const res = await fetch ( `http://127.0.0.1:${ server . port } /mcp` , {
683681 method : "GET" ,
684682 headers : {
@@ -692,8 +690,7 @@ describe("createMcpLoopbackServerConfig", () => {
692690
693691 it ( "acknowledges DELETE session teardown with 200 (stateless no-op)" , async ( ) => {
694692 server = await startMcpLoopbackServer ( 0 ) ;
695- const runtime = getActiveMcpLoopbackRuntime ( ) ;
696- const token = runtime ? resolveMcpLoopbackBearerToken ( runtime , false ) : undefined ;
693+ const token = getActiveMcpLoopbackRuntime ( ) ?. ownerToken ;
697694 const res = await fetch ( `http://127.0.0.1:${ server . port } /mcp` , {
698695 method : "DELETE" ,
699696 headers : token ? { authorization : `Bearer ${ token } ` } : { } ,
@@ -716,14 +713,32 @@ describe("createMcpLoopbackServerConfig", () => {
716713
717714 it ( "stays stateless: POST responses advertise no Mcp-Session-Id" , async ( ) => {
718715 server = await startMcpLoopbackServer ( 0 ) ;
719- const runtime = getActiveMcpLoopbackRuntime ( ) ;
720716 const res = await sendRaw ( {
721717 port : server . port ,
722- token : runtime ? resolveMcpLoopbackBearerToken ( runtime , false ) : undefined ,
718+ token : getActiveMcpLoopbackRuntime ( ) ?. ownerToken ,
723719 headers : { "content-type" : "application/json" , "x-session-key" : "agent:main:main" } ,
724720 body : JSON . stringify ( { jsonrpc : "2.0" , id : 1 , method : "tools/list" } ) ,
725721 } ) ;
726722 expect ( res . status ) . toBe ( 200 ) ;
727723 expect ( res . headers . get ( "mcp-session-id" ) ) . toBeNull ( ) ;
728724 } ) ;
725+
726+ it ( "rejects a browser-Origin GET before auth (403, no bearer)" , async ( ) => {
727+ server = await startMcpLoopbackServer ( 0 ) ;
728+ const res = await fetch ( `http://127.0.0.1:${ server . port } /mcp` , {
729+ method : "GET" ,
730+ headers : { origin : "https://evil.example" } ,
731+ } ) ;
732+ expect ( res . status ) . toBe ( 403 ) ;
733+ await res . body ?. cancel ( ) ;
734+ } ) ;
735+
736+ it ( "rejects a browser-Origin DELETE before auth (403, no bearer)" , async ( ) => {
737+ server = await startMcpLoopbackServer ( 0 ) ;
738+ const res = await fetch ( `http://127.0.0.1:${ server . port } /mcp` , {
739+ method : "DELETE" ,
740+ headers : { origin : "https://evil.example" } ,
741+ } ) ;
742+ expect ( res . status ) . toBe ( 403 ) ;
743+ } ) ;
729744} ) ;
0 commit comments