fix: redirect unauthorized_client errors per RFC 6749 Section 4.1.2.1#1816
Open
fix: redirect unauthorized_client errors per RFC 6749 Section 4.1.2.1#1816
Conversation
- Move `validate :redirect_uri` before `validate :client_supports_grant_flow` in PreAuthorization so the redirect URI is verified before an unauthorized_client error can fire. This prevents redirecting to an unvalidated (potentially attacker-controlled) URI. - Remove `:unauthorized_client` from `NON_REDIRECTABLE_STATES` so that when the client is known and its redirect URI is valid, an unauthorized_client response is sent via redirect as required by the spec. - Update `status` to return `:bad_request` for `unauthorized_client` (`:unauthorized` is only appropriate for `invalid_client`, which is an authentication failure). - Update specs to reflect the corrected behaviour. Fixes: #1578 Agent-Logs-Url: https://github.com/doorkeeper-gem/doorkeeper/sessions/d020e8cb-f3fa-4721-9b38-457c154eb533 Co-authored-by: nbulaj <[email protected]>
Copilot created this pull request from a session on behalf of
nbulaj
April 21, 2026 19:08
View session
Member
|
Addresses #1578 |
Member
|
@copilot tests are failing, analyze and fix them |
Member
|
@copilot hey, check why tests are failing and fix them |
…ized_client The unauthorized_client error is now redirected per RFC 6749 §4.1.2.1. Update the controller specs to assert the new redirect behaviour: - Non-API mode: response is a 302 redirect with error params in the URI fragment - API mode: JSON response with status/redirect_uri, HTTP 400 Also add a CHANGELOG.md entry. Agent-Logs-Url: https://github.com/doorkeeper-gem/doorkeeper/sessions/ba408183-296e-467b-a623-be19597424ae Co-authored-by: nbulaj <[email protected]>
Contributor
Author
The 6 failures were in
A CHANGELOG.md entry was also added (fixing the Changelog verifier failure).
Done — see the reply above. Fixed in 009c5fa (test updates + CHANGELOG) and 80c3a89 (strengthened assertion). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lib/doorkeeper/oauth/pre_authorization.rb— movevalidate :redirect_uribeforevalidate :client_supports_grant_flowlib/doorkeeper/oauth/error_response.rb— remove:unauthorized_clientfromNON_REDIRECTABLE_STATES; updatestatusspec/lib/oauth/pre_authorization_spec.rb— update validation-order testspec/lib/oauth/error_response_spec.rb— updateunauthorized_clientredirectability and status testsspec/controllers/authorizations_controller_spec.rb— update "when client can not use grant flow" tests for both non-API and API mode; strengthen redirect_uri assertion toinclude("error=unauthorized_client")CHANGELOG.md— add entry for the fix