oauthex: validate URL schemes in auth server metadata and DCR
Use URL scheme validation for remaining URL fields in auth datastructures (AuthServerMeta and ClientRegistrationMetadata), to prevent XSS attacks. By comparison, the typescript SDK doesn't validate introspection_endpoint, and I don't know why. Otherwise the implementations align. Fixes #526
This commit is contained in:
parent
6f6e196c27
commit
307e32c2b3
1 changed files with 387 additions and 0 deletions
|
|
@ -22,6 +22,10 @@ import (
|
|||
// Not supported:
|
||||
// - signed metadata
|
||||
//
|
||||
// Note: URL fields in this struct are validated by validateAuthServerMetaURLs to
|
||||
// prevent XSS attacks. If you add a new URL field, you must also add it to that
|
||||
// function.
|
||||
//
|
||||
// [RFC 8414]: https://tools.ietf.org/html/rfc8414)
|
||||
type AuthServerMeta struct {
|
||||
// GENERATED BY GEMINI 2.5.
|
||||
|
|
@ -144,9 +148,40 @@ func GetAuthServerMeta(ctx context.Context, issuerURL string, c *http.Client) (*
|
|||
return nil, fmt.Errorf("authorization server at %s does not implement PKCE", issuerURL)
|
||||
}
|
||||
|
||||
// Validate endpoint URLs to prevent XSS attacks (see #526).
|
||||
if err := validateAuthServerMetaURLs(asm); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return asm, nil
|
||||
}
|
||||
errs = append(errs, err)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to get auth server metadata from %q: %w", issuerURL, errors.Join(errs...))
|
||||
}
|
||||
|
||||
// validateAuthServerMetaURLs validates all URL fields in AuthServerMeta
|
||||
// to ensure they don't use dangerous schemes that could enable XSS attacks.
|
||||
func validateAuthServerMetaURLs(asm *AuthServerMeta) error {
|
||||
urls := []struct {
|
||||
name string
|
||||
value string
|
||||
}{
|
||||
{"authorization_endpoint", asm.AuthorizationEndpoint},
|
||||
{"token_endpoint", asm.TokenEndpoint},
|
||||
{"jwks_uri", asm.JWKSURI},
|
||||
{"registration_endpoint", asm.RegistrationEndpoint},
|
||||
{"service_documentation", asm.ServiceDocumentation},
|
||||
{"op_policy_uri", asm.OpPolicyURI},
|
||||
{"op_tos_uri", asm.OpTOSURI},
|
||||
{"revocation_endpoint", asm.RevocationEndpoint},
|
||||
{"introspection_endpoint", asm.IntrospectionEndpoint},
|
||||
}
|
||||
|
||||
for _, u := range urls {
|
||||
if err := checkURLScheme(u.value); err != nil {
|
||||
return fmt.Errorf("%s: %w", u.name, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue