Skip to content

[Bug]: MCP OAuth accepts a resource URI containing an empty fragment #35793

Closed as not planned

Description

@coygeek

Summary

MCP OAuth accepts a resource identifier with an empty fragment and continues authorization as if the fragment were absent. Resource identifiers containing any fragment must be rejected. This was reproduced through the real authorization service, with canonical, nonempty-fragment, relative-URI, and unrelated-host controls.

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. Register a synthetic public OAuth client with a loopback redirect using the real service.
  2. Submit a valid code authorization request with S256 PKCE and resource=https://mcp.example/mcp#.
  3. Compare it with the canonical resource, a nonempty fragment, a relative resource, and an unrelated host.

The final script reproduced the defect once. It invokes the checkout's actual implementation, uses only disposable local state and synthetic credentials, and leaves the checkout unchanged.

Save the following as repro-resource.mjs and run node repro-resource.mjs /path/to/checkout from any directory. Prerequisites are Node with native TypeScript support and the checkout's frozen-lockfile dependencies installed. The script creates its inputs under a temporary directory, redirects HOME, TMPDIR, and T3CODE_HOME there, and removes that directory on exit. Its controls must pass; exit 0 means the expected contract holds, exit 1 means the defect reproduced, and exit 2 means setup or a control was inconclusive.

Reproduction script: repro-resource.mjs
import { mkdtempSync, mkdirSync, rmSync, readFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { resolve, join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { createRequire } from 'node:module';
const checkout = resolve(process.argv[2] ?? '.');
const scratch = mkdtempSync(join(tmpdir(), 'mcp-resource-repro-'));
for (const name of ['home', 'tmp', 'state']) mkdirSync(join(scratch, name));
process.env.HOME = join(scratch, 'home');
process.env.TMPDIR = join(scratch, 'tmp');
process.env.T3CODE_HOME = join(scratch, 'state');
let status = 2;
try {
  console.log(`Node ${process.version}`);
  const req = createRequire(join(checkout, 'apps/server/package.json'));
  const pkg = (name) => import(pathToFileURL(req.resolve(name)).href);
  const src = (name) => import(pathToFileURL(join(checkout, 'apps/server/src', name)).href);
  const [Effect, Layer, NodeCrypto, OAuth, Auth, Secrets, Settings] = await Promise.all([
    pkg('effect/Effect'), pkg('effect/Layer'), pkg('@effect/platform-node/NodeCrypto'),
    src('auth/McpOAuth.ts'), src('auth/EnvironmentAuth.ts'),
    src('auth/ServerSecretStore.ts'), src('serverSettings.ts'),
  ]);
  console.log(`Effect ${JSON.parse(readFileSync(req.resolve('effect/package.json'), 'utf8')).version}`);
  const layer = OAuth.layer.pipe(Layer.provide(Layer.mergeAll(
    Layer.mock(Auth.EnvironmentAuth)({}),
    Layer.mock(Secrets.ServerSecretStore)({ getOrCreateRandom: () => Effect.succeed(new Uint8Array(32).fill(1)) }),
    Settings.layerTest(), NodeCrypto.layer,
  )));
  status = await Effect.runPromise(Effect.gen(function* () {
    const oauth = yield* OAuth.McpOAuth;
    const client = yield* oauth.register({ client_name: 'Resource validation probe', redirect_uris: ['http://localhost/callback'] });
    const validate = (resource) => oauth.validateAuthorization({
      urls: { issuer: 'https://mcp.example', resource: 'https://mcp.example/mcp' },
      request: { response_type: 'code', client_id: client.clientId, redirect_uri: 'http://localhost/callback', code_challenge: 'a'.repeat(43), code_challenge_method: 'S256', resource },
    }).pipe(Effect.map(() => 'accepted'), Effect.catch(error => Effect.succeed(error.error ?? error._tag)));
    const canonical = yield* validate('https://mcp.example/mcp');
    const nonempty = yield* validate('https://mcp.example/mcp#section');
    const relative = yield* validate('/mcp');
    const other = yield* validate('https://other.example/mcp');
    const empty = yield* validate('https://mcp.example/mcp#');
    console.log(JSON.stringify({ canonical, nonemptyFragment: nonempty, relative, otherAudience: other, emptyFragment: empty }));
    if (canonical !== 'accepted' || nonempty !== 'invalid_target' || relative !== 'invalid_target' || other !== 'invalid_target') return 2;
    return empty === 'invalid_target' ? 0 : empty === 'accepted' ? 1 : 2;
  }).pipe(Effect.provide(layer)));
} catch (error) {
  console.error(error);
} finally {
  rmSync(scratch, { recursive: true, force: true });
}
console.log(status === 0 ? 'RESULT: expected behavior' : status === 1 ? 'RESULT: defect reproduced' : 'RESULT: inconclusive');
process.exitCode = status;

Expected behavior

RFC 8707 §2 requires an absolute resource URI without a fragment component. An empty fragment is still a fragment component. Reject the request rather than continuing authorization; the existing nonempty-fragment control returns invalid_target. The restoration check is that the empty-fragment case is also rejected while the canonical control remains accepted.

Actual behavior

McpOAuth.validateAuthorization accepts https://mcp.example/mcp# and resolves it to https://mcp.example/mcp. The equivalent resource with #section is rejected with invalid_target. The HTTP authorization route uses this service after decoding the resource string.

Impact

Minor bug or occasional failure

Impact: P2 - The OAuth boundary accepts a malformed resource identifier that the supported resource-indicator contract prohibits. Scope is the empty-fragment input; this run does not establish unauthorized access or a cross-resource attack. Clients can avoid the failure by sending the canonical URI without a fragment. Downstream client recovery consequences were not measured.

Version or commit

T3 Code commit 59e64eef881632a23f89c4138bcf37f23d92bf93; the checkout's server package is 0.1.9.

Environment

Observed with Node v26.12.1 on macOS arm64 and the pinned Effect 4.1.3. No live profile, provider turn, deployed service, or external consent flow was used. NOT_ENOUGH_INFO: other runtimes and platforms were not exercised; running the same script would establish them.

Evidence

Evidence provenance: observed and static. Local verification: reproduced. Reproduction completeness: complete for the bounded local service or transport fixture. Expected source and failure source are linked below. Missing fact: behavior in other client applications and deployed environments was not exercised.

The final run printed:

Node v26.12.1
Effect 4.1.3
{"canonical":"accepted","nonemptyFragment":"invalid_target","relative":"invalid_target","otherAudience":"invalid_target","emptyFragment":"accepted"}
RESULT: defect reproduced

Source evidence: apps/server/src/auth/McpOAuth.ts#L131-L139 checks URL.hash, which is empty both when a fragment is absent and when the URI ends with #; apps/server/src/auth/McpOAuth.ts#L397-L407 admits the resource and stores the canonical resource. The same helper is used during token exchange at apps/server/src/auth/McpOAuth.ts#L534-L541. The supported HTTP authorization path calls the service at apps/server/src/auth/mcpOAuthHttp.ts#L117-L153. Only authorization validation was exercised dynamically; token-exchange handling is source evidence.

Restoration check

Run the included script and require exit 0 with RESULT: expected behavior; all controls must remain successful. The expected behavior section defines the same contract to restore.

Workaround

Send the canonical resource URI without a fragment.

References

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