cimd

package
v0.69.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cimd implements fetching and validation of OAuth 2.0 Client ID Metadata Documents (CIMD) per draft-ietf-oauth-client-id-metadata-document.

This package is a sub-package of pkg/oauthproto and is allowed to import pkg/networking (for SSRF utilities) without violating the leaf-package invariant of the parent package.

Index

Constants

This section is empty.

Variables

View Source
var ErrDocumentUnavailable = errors.New("client metadata document unavailable")

ErrDocumentUnavailable marks a fetch failure in which the document host delivered no usable response or answered with a 5xx, 408, or 429 status: a resolver, dial, TLS, or SSRF-guard failure, a timeout, a 200 whose body was cut short or stalled, a server error, a request timeout, or a rate limit. Nothing is known about the document itself in these cases, so a caller that holds an earlier copy may keep serving it for a bounded time of its own choosing. Every other failure is definitive and never carries this error: an invalid client_id URL, a 3xx or any other 4xx status (whatever happened to its body), an unexpected content type, a body that is not JSON, or a document that ValidateClientMetadataDocument rejects. Check with errors.Is.

Functions

func ValidateClientMetadataDocument

func ValidateClientMetadataDocument(doc *ClientMetadataDocument, fetchedFrom string) error

ValidateClientMetadataDocument validates a parsed ClientMetadataDocument against the URL it was fetched from. Per the CIMD draft spec, the client_id field must exactly equal the URL — no normalization is applied, because allowing normalization would permit subtle spoofing attacks where a document at URL A claims the identity of URL B.

Types

type ClientMetadataDocument

type ClientMetadataDocument struct {
	// Required
	ClientID     string   `json:"client_id"`
	RedirectURIs []string `json:"redirect_uris"`

	// Recommended
	ClientName string `json:"client_name,omitempty"`
	LogoURI    string `json:"logo_uri,omitempty"`
	ClientURI  string `json:"client_uri,omitempty"`

	// Optional
	TosURI                  string   `json:"tos_uri,omitempty"`
	PolicyURI               string   `json:"policy_uri,omitempty"`
	GrantTypes              []string `json:"grant_types,omitempty"`
	ResponseTypes           []string `json:"response_types,omitempty"`
	Scope                   string   `json:"scope,omitempty"`
	TokenEndpointAuthMethod string   `json:"token_endpoint_auth_method,omitempty"`
	// TokenEndpointAuthMethodsSupported is not part of the CIMD draft itself;
	// it is defined by OpenID Connect RP Metadata Choices 1.0 as the plural
	// counterpart of TokenEndpointAuthMethod, listing every method the client
	// supports while TokenEndpointAuthMethod names its preferred one. Live
	// clients (e.g. ChatGPT) publish it alongside a stricter singular
	// preference the client_id-issuing party does not control per-AS; the
	// decorator in pkg/authserver/storage uses it to negotiate a mutually
	// supported method instead of rejecting the document outright (#6278).
	TokenEndpointAuthMethodsSupported []string `json:"token_endpoint_auth_methods_supported,omitempty"`
	ApplicationType                   string   `json:"application_type,omitempty"`
	PostLogoutRedirectURIs            []string `json:"post_logout_redirect_uris,omitempty"`
}

ClientMetadataDocument represents an OAuth 2.0 Client ID Metadata Document per draft-ietf-oauth-client-id-metadata-document.

func FetchClientMetadataDocument

func FetchClientMetadataDocument(ctx context.Context, rawURL string) (*ClientMetadataDocument, error)

FetchClientMetadataDocument fetches and validates a Client ID Metadata Document from the given URL. The URL must use the HTTPS scheme (http://localhost is accepted in development). The document is fetched with a 5-second timeout, redirects disabled, a 10 KB body cap, and SSRF protection via a per-dial IP check. After fetching, ValidateClientMetadataDocument is called and any validation error is returned. A failure in which the host delivered no usable response or answered 5xx, 408, or 429 wraps ErrDocumentUnavailable; see that error for the exact split between transient and definitive failures.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL