Skip to content

Commit da3535b

Browse files
Compare auth server metadata issuer ignoring trailing slash (#955)
oauthex/auth_meta.go: fixes metadata issuer comparison to ignore trailing slash difference Google's gmail MCP server returns `https://accounts.google.com/` as the Authorization Server in the Protected Resource Metadata, but returns `https://accounts.google.com` in the Auth Server Metadata. This causes a comparison failure per rfc8414 section-3.3: Authorization Server Metadata Validation. The authorization server URL is meant to be a base to build other URLs from, it does not seem necessary to enforce that the trailing slash (or lack thereof) matches with the issuer URL. Please see #953 for more details. Fixes #953 --------- Co-authored-by: Guglielmo Colombo <guglielmoc@google.com>
1 parent 9f5e89f commit da3535b

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

oauthex/auth_meta.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"errors"
1313
"fmt"
1414
"net/http"
15+
"strings"
1516
)
1617

1718
// AuthServerMeta represents the metadata for an OAuth 2.0 authorization server,
@@ -145,7 +146,7 @@ func GetAuthServerMeta(ctx context.Context, metadataURL, issuer string, c *http.
145146
}
146147
return nil, fmt.Errorf("%v", err) // Do not expose error types.
147148
}
148-
if asm.Issuer != issuer {
149+
if strings.TrimRight(asm.Issuer, "/") != strings.TrimRight(issuer, "/") {
149150
// Validate the Issuer field (see RFC 8414, section 3.3).
150151
return nil, fmt.Errorf("metadata issuer %q does not match issuer URL %q", asm.Issuer, issuer)
151152
}

oauthex/auth_meta_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ func TestAuthMetaParse(t *testing.T) {
3535
func TestGetAuthServerMetaPKCESupport(t *testing.T) {
3636
ctx := context.Background()
3737
tests := []struct {
38-
name string
39-
hasPKCESupport bool
40-
wantError string
38+
name string
39+
hasPKCESupport bool
40+
wantError string
41+
issuerWithTrailingSlash bool
4142
}{
4243
{
4344
name: "server_with_pkce_support",
@@ -48,6 +49,12 @@ func TestGetAuthServerMetaPKCESupport(t *testing.T) {
4849
hasPKCESupport: false,
4950
wantError: "does not implement PKCE",
5051
},
52+
{
53+
// ProtectedResourceMetadata may contain AuthorizationServers with a trailing slash (see Issue #953)
54+
name: "issuer_with_trailing_slash",
55+
hasPKCESupport: true,
56+
issuerWithTrailingSlash: true,
57+
},
5158
}
5259

5360
for _, tt := range tests {
@@ -85,6 +92,9 @@ func TestGetAuthServerMetaPKCESupport(t *testing.T) {
8592
u, _ := url.Parse(ts.URL)
8693
issuer := "https://localhost:" + u.Port()
8794
metadataURL := issuer + "/.well-known/oauth-authorization-server"
95+
if tt.issuerWithTrailingSlash {
96+
issuer += "/"
97+
}
8898

8999
// The fake server presents a cert for example.com; set ServerName accordingly.
90100
httpClient := ts.Client()

0 commit comments

Comments
 (0)