Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion oauthex/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func (e *ClientRegistrationError) Error() string {
return fmt.Sprintf("registration failed: %s (%s)", e.ErrorCode, e.ErrorDescription)
}

// maxRegistrationResponseBytes bounds the dynamic client registration response
// body read from the authorization server.
const maxRegistrationResponseBytes = 1 << 20 // 1 MiB

// RegisterClient performs Dynamic Client Registration according to RFC 7591.
func RegisterClient(ctx context.Context, registrationEndpoint string, clientMeta *ClientRegistrationMetadata, c *http.Client) (*ClientRegistrationResponse, error) {
if registrationEndpoint == "" {
Expand Down Expand Up @@ -204,7 +208,7 @@ func RegisterClient(ctx context.Context, registrationEndpoint string, clientMeta
}
defer resp.Body.Close()

body, err := io.ReadAll(resp.Body)
body, err := io.ReadAll(io.LimitReader(resp.Body, maxRegistrationResponseBytes))
if err != nil {
return nil, fmt.Errorf("failed to read registration response body: %w", err)
}
Expand Down
Loading