Skip to content

Commit 8898db9

Browse files
fix(http): terminate unknown resource metadata routes
Prevent unrecognized protected-resource metadata paths from falling through to the MCP root mount and producing recursive authentication challenges.\n\nRefs #3095\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c393e4a commit 8898db9

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

pkg/http/oauth/oauth.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (h *AuthHandler) RegisterRoutes(r chi.Router) {
100100
r.Handle(path, h.metadataHandler())
101101
}
102102
}
103+
r.Handle(OAuthProtectedResourcePrefix+"/*", http.NotFoundHandler())
103104
}
104105

105106
func (h *AuthHandler) metadataHandler() http.Handler {

pkg/http/oauth/oauth_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ func TestRegisterRoutes(t *testing.T) {
573573
}
574574
}
575575
}
576+
577+
req := httptest.NewRequest(http.MethodGet, OAuthProtectedResourcePrefix+"/mcp/unknown", nil)
578+
rec := httptest.NewRecorder()
579+
router.ServeHTTP(rec, req)
580+
assert.Equal(t, http.StatusNotFound, rec.Code)
576581
}
577582

578583
func TestSupportedScopes(t *testing.T) {

pkg/http/server_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ func TestOAuthChallengeMetadataRouteContracts(t *testing.T) {
258258
assert.Equal(t, baseURL+expectedResourcePath, metadata["resource"])
259259
})
260260
}
261+
262+
req := httptest.NewRequest(
263+
http.MethodGet,
264+
oauth.OAuthProtectedResourcePrefix+"/mcp/unknown",
265+
nil,
266+
)
267+
req.Header.Set("Origin", "https://confer.to")
268+
rec := httptest.NewRecorder()
269+
router.ServeHTTP(rec, req)
270+
assert.Equal(t, http.StatusNotFound, rec.Code)
271+
assert.Equal(t, "*", rec.Header().Get("Access-Control-Allow-Origin"))
272+
assert.Empty(t, rec.Header().Get("WWW-Authenticate"))
261273
}
262274

263275
func TestInitGlobalToolScopeMapUsesHost(t *testing.T) {

0 commit comments

Comments
 (0)