fix(coderd): ignore leading zeros in MCP OAuth2 resource origin ports
RFC 9110 section 4.3.1 removes leading zeros from an origin's port, so a server URL on port 0443 now matches an advertised resource on the default HTTPS port.
This commit is contained in:
1 parent
ef2df2c4e7
commit
2d6abfac49
2 files changed
+11
-1
No files matched your search
+5
-1
@@ -2004,7 +2004,11 @@ func sameHost(a, b string) bool {
|
||||
|
||||
func portOrDefault(u *url.URL) string {
|
||||
if port := u.Port(); port != "" {
|
||||
return port
|
||||
// An origin's port has no leading zeros (RFC 9110 section 4.3.1).
|
||||
if trimmed := strings.TrimLeft(port, "0"); trimmed != "" {
|
||||
return trimmed
|
||||
}
|
||||
return "0"
|
||||
}
|
||||
switch strings.ToLower(u.Scheme) {
|
||||
case "http":
|
||||
|
||||
@@ -381,6 +381,12 @@ func TestMCPOAuth2ResourceIndicator(t *testing.T) {
|
||||
advertised: []string{"http://mcp.example.com:80/mcp"},
|
||||
want: "http://mcp.example.com:80/mcp",
|
||||
},
|
||||
{
|
||||
name: "PortLeadingZerosAreIgnored",
|
||||
serverURL: "https://mcp.example.com:0443/mcp",
|
||||
advertised: []string{"https://mcp.example.com/mcp"},
|
||||
want: "https://mcp.example.com/mcp",
|
||||
},
|
||||
{
|
||||
name: "EscapedSlashIsNotSegmentBoundary",
|
||||
serverURL: "https://mcp.example.com/mcp%2Ftenant",
|
||||
|
||||
Reference in new issue
Block a user