Skip to content

[Bug]: Disallowed MCP origins receive 401 or 204 before the required 403 rejection #35791

Closed as not planned

Description

@coygeek

Summary

The MCP endpoint does not consistently return the specified forbidden response for a disallowed browser origin. An isolated HTTP reproduction found that authentication and CORS handling return different statuses before the MCP transport can reject the origin. Authenticated requests still receive the correct rejection, so this report concerns protocol response semantics and does not establish unauthorized tool execution.

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Use the stated checkout with its locked dependencies installed.
  2. Run the script below, which starts an ephemeral loopback HTTP server using McpHttpServer.layerMcpTransport, layerBrowserApiCors, and layerHttpCompression. It substitutes only the credential registry with an in-memory synthetic credential and uses empty tool registration.
  3. Compare the Origin-less discovery control, authenticated disallowed-Origin control, unauthenticated disallowed-Origin POST, and disallowed-Origin preflight.

The final script reproduced this deterministically in one run. Earlier exploratory probes observed the same statuses while checking discovery, headers, and MRTR; two earlier fixture attempts stopped on missing fixture annotations and an unsupported GET body before completing the full probe, and were corrected before the final script.

Save the following as repro.mjs outside the checkout and run node --experimental-strip-types repro.mjs /path/to/checkout. Prerequisites are Node with TypeScript stripping, Git, and the checkout's installed locked dependencies. The script creates disposable HOME, TMPDIR, and T3 state directories, uses no real credentials, removes its state on exit, and leaves the checkout unchanged. Exit 0 means both requests return the required 403, exit 1 means the response mismatch is reproduced, and exit 2 means setup or a control failed.

Reproduction script: repro.mjs
import { createRequire } from 'node:module';
import { pathToFileURL } from 'node:url';
import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import assert from 'node:assert/strict';
import {execFileSync} from 'node:child_process';
const checkout = process.argv[2];
if (!checkout) throw Error('checkout argument required');
const require = createRequire(checkout+'/apps/server/package.json');
const dep = x=>import(pathToFileURL(require.resolve(x)).href);
const local = x=>import(pathToFileURL(checkout+'/apps/server/src/'+x).href);
const [Effect, Layer, Schema, {McpSchema,McpServer,Tool,Toolkit}, {HttpBody,HttpClient,HttpClientRequest,HttpRouter}, {NodeHttpServer}, NodeServices, NodeCrypto, McpHttpServer, McpSessionRegistry, McpToolAccess, ServerSettings, ServerConfig, ServerHttp] = await Promise.all([
 dep('effect/Effect'),dep('effect/Layer'),dep('effect/Schema'),dep('effect/ai'),dep('effect/http'),dep('@effect/platform-node'),dep('@effect/platform-node/NodeServices'),dep('@effect/platform-node/NodeCrypto'),local('mcp/McpHttpServer.ts'),local('mcp/McpSessionRegistry.ts'),local('mcp/McpToolAccess.ts'),local('serverSettings.ts'),local('config.ts'),local('http.ts')]);
const scratch=mkdtempSync(tmpdir()+'/g08-probe-');
for(const name of ['home','tmp','state'])mkdirSync(scratch+'/'+name);
process.env.HOME=scratch+'/home';process.env.TMPDIR=scratch+'/tmp';process.env.T3CODE_HOME=scratch+'/state';
const token='fixture';
const scope={environmentId:'environment-probe',requestNamespace:'probe',thread:{threadId:'thread-probe',providerSessionId:'probe',providerInstanceId:'codex'},client:undefined,capabilities:new Set(['orchestration']),issuedAt:1};
const registration=Layer.empty;
const transport=McpHttpServer.layerMcpTransport(registration).pipe(
 Layer.provide(ServerSettings.layerTest()),
 Layer.provide(Layer.mock(McpSessionRegistry.McpSessionRegistry)({resolve:presented=>Effect.succeed(presented===token?scope:undefined)})),
 Layer.provide(ServerHttp.layerBrowserApiCors),Layer.provide(ServerHttp.layerHttpCompression),
 Layer.provide(ServerConfig.layerTest(scratch,scratch+'/state')),Layer.provide(Layer.merge(NodeServices.layer,NodeCrypto.layer)));
const meta=(version='2026-07-28',capabilities={})=>({'io.modelcontextprotocol/protocolVersion':version,'io.modelcontextprotocol/clientCapabilities':capabilities,'io.modelcontextprotocol/clientInfo':{name:'probe',version:'1.0.0'}});
const outputs=[];
console.log('node '+process.version);
console.log(execFileSync('git',['--version'],{encoding:'utf8'}).trim());
console.log('T3 commit '+execFileSync('git',['-C',checkout,'rev-parse','HEAD'],{encoding:'utf8'}).trim());
console.log('effect '+require('effect/package.json').version);
console.log('platform '+process.platform+' '+process.arch);
try{
 await Effect.runPromise(Effect.scoped(Effect.gen(function*(){
  yield* HttpRouter.serve(transport,{disableListenLog:true,disableLogger:true}).pipe(Layer.build);
  const http=yield* HttpClient.HttpClient;
  let id=0;
  const send=(label,method,params,headerOverrides={},verb='POST',authorized=true)=>Effect.gen(function*(){
   const headers={accept:'application/json, text/event-stream','mcp-protocol-version':'2026-07-28','mcp-method':method,...(params?.name===undefined?{}:{'mcp-name':params.name}),...(authorized?{authorization:'Bearer '+token}:{}),...headerOverrides};
   for(const key in headers)if(headers[key]===null)delete headers[key];
   const response=yield* http.execute(HttpClientRequest.make(verb)('/mcp',{headers,...(verb==='GET'||verb==='HEAD'?{}:{body:HttpBody.text(JSON.stringify({jsonrpc:'2.0',id:++id,method,params}),'application/json')})}));
   const text=yield* response.text; const data=text?JSON.parse(text):null;
   const row={label,status:response.status,data};outputs.push(row);console.log(JSON.stringify(row));return row;
  });
  const control=yield* send('control: Origin-less authenticated discovery','server/discover',{_meta:meta()});
  if(control.status!==200 || !control.data?.result?.supportedVersions?.includes('2026-07-28'))throw Error('discovery control failed');
  const denied=yield* send('control: authenticated invalid Origin','server/discover',{_meta:meta()},{origin:'https://untrusted.invalid'});
  if(denied.status!==403)throw Error('authenticated Origin control failed');
  const unauthenticated=yield* send('unauthenticated invalid Origin','server/discover',{_meta:meta()},{origin:'https://untrusted.invalid'},'POST',false);
  const preflight=yield* send('preflight invalid Origin','server/discover',{_meta:meta()},{origin:'https://untrusted.invalid','access-control-request-method':'POST','access-control-request-headers':'content-type,mcp-method,mcp-protocol-version'},'OPTIONS',false);
  process.exitCode=unauthenticated.status===403 && preflight.status===403?0:1;
 })).pipe(Effect.provide(NodeHttpServer.layerTest)));
 console.log(process.exitCode===1?'RESULT: defect reproduced':'RESULT: expected behavior');
}catch(error){console.error('Setup or control failed: '+error.message);console.log('RESULT: inconclusive');process.exitCode=2;}finally{rmSync(scratch,{recursive:true,force:true})}

Expected behavior

Both requests should return HTTP 403 when a present Origin is disallowed. The MCP 2026-07-28 Streamable HTTP Security & Endpoint contract requires Origin validation on all incoming connections and specifies HTTP 403 for an invalid present Origin. T3 configures no allowed origins on its MCP transport; Effect 4.1.3 treats every present Origin as disallowed in that configuration.

Actual behavior

With T3's MCP transport composed with its production CORS and compression layers, a POST to /mcp carrying Origin: https://untrusted.invalid and no credential returns HTTP 401. An OPTIONS preflight carrying the same origin returns HTTP 204. The control request using a synthetic valid credential and that origin returns HTTP 403; an Origin-less authenticated discovery request succeeds with HTTP 200.

Impact

Minor bug or occasional failure

Impact: P3 - The observed defect changes rejection status semantics, without allowing a tool call or returning protected MCP data in the tested cases.

This affects requests rejected by authentication or answered by global CORS before transport admission. The authenticated disallowed-Origin control returns 403 and no DNS rebinding or authorization bypass was established. No normal authenticated native-client workflow failed. NOT_ENOUGH_INFO: downstream clients or monitoring that depend on the mandated status were not exercised; a client integration test would establish that reach. Origin-less authenticated requests are an observed working control.

Version or commit

T3 Code package version 0.1.9, commit 59e64eef881632a23f89c4138bcf37f23d92bf93; locked [email protected].

Environment

Observed on macOS arm64, Node v26.12.1, Git 2.56.0. The reproduction imports the checkout's existing dependencies without installing or updating them.

Interface: MCP: Streamable HTTP /mcp.

Earliest failure stage: Integration or transport.

Logs or stack traces

The final script printed the following relevant results; the transient warning timestamp is omitted. The authorization token is synthetic and not printed.

node v26.12.1
git version 2.56.0
T3 commit 59e64eef881632a23f89c4138bcf37f23d92bf93
effect 4.1.3
platform darwin arm64
control: Origin-less authenticated discovery -> 200, supportedVersions [2025-06-18,2026-07-28]
control: authenticated invalid Origin -> 403
unauthenticated invalid Origin -> 401, invalid_mcp_credential
preflight invalid Origin -> 204
RESULT: defect reproduced

Source evidence: apps/server/src/mcp/McpHttpServer.ts#L236-L283 returns the authentication response before executing the transport; apps/server/src/http.ts#L256-L273 installs global browser CORS; apps/server/src/server.ts#L803-L828 mounts the MCP route and apps/server/src/server.ts#L865-L867 supplies the global middleware. The pinned dependency's src/ai/McpServer.ts lines 2991-3013 and 3170-3175 do implement the Origin guard and return 403 when reached; the guard itself is not missing from Effect.

Restoration check

The same script should exit 0 after both disallowed-Origin requests return 403 while the Origin-less discovery control remains successful.

Workaround

Origin-less authenticated discovery is an observed working control. No workaround was tested that changes the invalid-Origin status without changing server code.

Activity

  1. added
    vouch:denounced
    on Nov 13, 2026
  2. maria-rcks commented on Nov 15, 2026

    @maria-rcks
    Collaborator

    Note

    Written by claude-fable-5-2 on behalf of Maria

    Closing: this account is denounced in .github/VOUCHED.td for filing automated issues faster than maintainers can triage them. A fix PR that links this issue is not affected by this close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:denounced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions