Skip to content

Accept a trailing slash on an origin-only DCR issuer - #7292

Merged
ChrisJBurns merged 2 commits into
mainfrom
worktree-implement-issue-7289
Nov 25, 2026
Merged

ChrisJBurns merged 2 commits into
mainfrom
worktree-implement-issue-7289

Conversation

@reyortiz3

@reyortiz3 reyortiz3 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A DCR upstream configured with dcrConfig.discoveryUrl could not register against servers built on FastMCP's OAuth proxy. Those servers publish "issuer": "https://host.example.com/" for a root deployment, while ToolHive derives https://host.example.com from the discovery URL and compared the two byte for byte. Registration failed with issuer mismatch (RFC 8414 §3.3).
  • fetchDiscoveryDocument now compares issuers with a new issuersEqual helper. For origin-only issuers it treats an empty path and / as equal (RFC 3986 §6.2.3).
  • The check stays as strict as before where it guards against mix-up attacks: scheme, host and port must match exactly, and an issuer with a path keeps byte-exact equality, including a trailing slash. A query, fragment or userinfo on either side still mismatches.
  • fetchDiscoveryDocument is shared, so the relaxation applies to both callers: the dcrConfig.discoveryUrl path (FetchAuthorizationServerMetadataFromURL) and the CLI remote-server DCR path (FetchAuthorizationServerMetadata, used from pkg/auth/discovery).
  • The DiscoveryURL field comment, the FetchAuthorizationServerMetadataFromURL doc comment and the DCR resolver comment no longer describe the check as byte-exact, and the swagger and SDK docs are regenerated to match.

Fixes #7289

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

task test cannot be scoped to one package, so I ran the full suite. Its only failure was the unrelated pkg/networking TestValidateCallbackPort ("OAuth callback port 8090 is already in use"), caused by a port already bound on my machine. The test output hides passing packages, so CI is the first confirmation that the new tests ran and passed.

Changes

File Change
pkg/oauthproto/discovery.go Compare issuers with issuersEqual instead of !=, update the doc comment
pkg/oauthproto/discovery_test.go Table-driven TestIssuersEqual, plus an end-to-end fetch against a server that publishes a trailing-slash issuer
pkg/authserver/config.go DiscoveryURL comment describes the relaxed issuer check
pkg/auth/dcr/resolver.go Comment no longer calls the check byte-exact
docs/server/*, sdk/go/* Regenerated from the DiscoveryURL comment

Does this introduce a user-facing change?

Yes.

This applies to both DCR discovery paths: dcrConfig.discoveryUrl and the CLI remote-server discovery.

Before: an upstream whose metadata says "issuer": "https://host.example.com/" was rejected when the expected issuer was https://host.example.com, and the upstream was unusable.

After: the two forms are accepted as the same issuer. Every other mismatch is still rejected, including different host, scheme or port, and /tenant versus /tenant/.

Special notes for reviewers

  • issuersEqual also rejects userinfo, a bare ?, opaque URLs and an empty host on either side. That is stricter than the sketch in the issue.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Nov 24, 2026
jerm-dro
jerm-dro previously approved these changes Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.93%. Comparing base (faa0076) to head (d3ddc49).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7292   +/-   ##
=======================================
  Coverage   81.92%   81.93%           
=======================================
  Files         922      922           
  Lines       93314    93352   +38     
=======================================
+ Hits        76451    76490   +39     
+ Misses      16858    16857    -1     
  Partials        5        5           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relaxation looks right to me: it only applies when both sides are origin-only, scheme and host (including port) must still match, and path issuers keep byte-exact equality. The returned md.Issuer with the trailing slash doesn't leak anywhere either, since endpointsFromMetadata and the registrationEndpointServerSupplied authority check use upstreamIssuer derived from the operator's discovery URL, not the document's issuer.

Two things on the PR as a whole:

  1. "must exactly match" is still the documented contract. I'd fold the DiscoveryURL field comment in pkg/authserver/config.go into this PR rather than a follow-up: the regenerated swagger/CRD text is what operators read, and the repo guidance is to document operator-observable behaviour in the same PR. Two more comments in code this PR already touches say the same thing:

    • FetchAuthorizationServerMetadataFromURL doc comment (pkg/oauthproto/discovery.go, "issuer field must exactly match the caller-supplied expectedIssuer").
    • deriveExpectedIssuerFromDiscoveryURL in pkg/auth/dcr/resolver.go, which describes the "§3.3 byte-equality check".
  2. Scope is wider than the summary says. fetchDiscoveryDocument is shared, so the relaxation also applies to FetchAuthorizationServerMetadata, i.e. the CLI remote-server DCR path in pkg/auth/discovery/discovery.go, not only dcrConfig.discoveryUrl. The behaviour is fine there too; worth a line in the PR body so reviewers know both paths changed.

Comment thread pkg/oauthproto/discovery.go Resolved
Comment thread pkg/oauthproto/discovery_test.go Resolved
@aponcedeleonch

Copy link
Copy Markdown
Member

Thanks for the review. Both points are in 33c27cf.

  1. Updated the DiscoveryURL field comment, the FetchAuthorizationServerMetadataFromURL doc comment and the comment in deriveExpectedIssuerFromDiscoveryURL so none of them describe the check as byte-exact anymore. Ran task docs, so the swagger and SDK text operators read now matches. There is no CRD copy of that field, so nothing changed under the operator.
  2. Added a line to the summary and the user-facing section saying the relaxation also covers the CLI remote-server DCR path through FetchAuthorizationServerMetadata.

reyortiz3 and others added 2 commits November 25, 2026 11:54
FastMCP-based authorization servers publish "issuer": "https://host/" for a root deployment, while ToolHive derives "https://host" from the discovery URL and compared the two byte for byte, so registration failed. Treat an empty path and "/" as equal for origin-only issuers (RFC 3986 section 6.2.3). Scheme, host and port still match exactly, and an issuer with a path keeps byte-exact equality.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Address review feedback on the trailing-slash issuer relaxation. The
DiscoveryURL field, FetchAuthorizationServerMetadataFromURL and the DCR
resolver still described the RFC 8414 section 3.3 check as byte-exact,
which is no longer the contract operators get. Update those comments and
regenerate the swagger and SDK docs so the published field description
matches the behaviour.

Also require a host in issuersEqual so an empty issuer never counts as
origin-only, and replace the unparsable test case with one that only
the parse-error branch rejects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Nov 25, 2026
@aponcedeleonch
aponcedeleonch force-pushed the worktree-implement-issue-7289 branch from 33c27cf to d3ddc49 Compare November 25, 2026 10:00
@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 25, 2026
@ChrisJBurns
ChrisJBurns merged commit 74e4ad7 into main Nov 25, 2026
47 checks passed
@ChrisJBurns
ChrisJBurns deleted the worktree-implement-issue-7289 branch November 25, 2026 12:51
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

5 participants