Limit redirect URIs on OAuth dynamic client registration
What does this MR do and why?
POST /oauth/register (OAuth dynamic client registration) doesn't require sign-in, and it stores every redirect URI it receives in oauth_applications.redirect_uri. Nothing limits how many URIs a registration has or how long they are.
This MR rejects a registration with invalid_client_metadata when:
redirect_uriscontains anything other than strings- it has more than 100 redirect URIs. URIs are counted after splitting on whitespace, as Doorkeeper does when it stores them.
- any URI is longer than 2048 characters
Real MCP clients register 1 to 4 URIs, so 100 leaves plenty of headroom. The limits are constants in Oauth::DynamicRegistrationsController (MAX_REDIRECT_URIS and MAX_REDIRECT_URI_LENGTH), not application settings.
The check is behind the oauth_dynamic_registration_redirect_uri_limits flag (gitlab_com_derisk, default off), so it can be turned off quickly if a client breaks.
A follow-up MR adds cleanup of unused dynamic applications.
References
How to set up and validate locally
- In the Rails console, enable the flag:
Feature.enable(:oauth_dynamic_registration_redirect_uri_limits) - Register a client with 101 redirect URIs:
The response is
curl -s -X POST http://gdk.test:3000/oauth/register -H 'Content-Type: application/json' \ -d "{\"client_name\":\"test\",\"redirect_uris\":[$(for i in $(seq 1 101); do printf '"http://localhost/%s",' $i; done | sed 's/,$//')]}"400with"error_description":"redirect_uris must contain at most 100 URIs". - Repeat with 100 URIs. The response is
201. - Register a client with one redirect URI longer than 2048 characters. The response is
400with"error_description":"each redirect URI must be at most 2048 characters". - Disable the flag and repeat step 2. The response is
201.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.