Skip to content

fix: redirect unauthorized_client errors per RFC 6749 Section 4.1.2.1#1816

Open
Copilot wants to merge 3 commits intomainfrom
copilot/validate-issue-1578
Open

fix: redirect unauthorized_client errors per RFC 6749 Section 4.1.2.1#1816
Copilot wants to merge 3 commits intomainfrom
copilot/validate-issue-1578

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

  • Understand the bug and validation flow
  • lib/doorkeeper/oauth/pre_authorization.rb — move validate :redirect_uri before validate :client_supports_grant_flow
  • lib/doorkeeper/oauth/error_response.rb — remove :unauthorized_client from NON_REDIRECTABLE_STATES; update status
  • spec/lib/oauth/pre_authorization_spec.rb — update validation-order test
  • spec/lib/oauth/error_response_spec.rb — update unauthorized_client redirectability and status tests
  • spec/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 to include("error=unauthorized_client")
  • CHANGELOG.md — add entry for the fix
  • Parallel validation — Code Review ✅, CodeQL ✅

- 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]>
@nbulaj
Copy link
Copy Markdown
Member

nbulaj commented Apr 22, 2026

Addresses #1578

@nbulaj
Copy link
Copy Markdown
Member

nbulaj commented Apr 22, 2026

@copilot tests are failing, analyze and fix them

@nbulaj
Copy link
Copy Markdown
Member

nbulaj commented Apr 23, 2026

@copilot hey, check why tests are failing and fix them

Copilot AI and others added 2 commits April 23, 2026 07:03
…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]>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 23, 2026

@copilot tests are failing, analyze and fix them

Fixed in 009c5fa and 80c3a89.

The 6 failures were in spec/controllers/authorizations_controller_spec.rb — the "when client can not use grant flow" tests in both non-API and API mode were still asserting the old (non-RFC-compliant) 401 JSON error response. Since unauthorized_client is now redirectable, those tests needed updating:

  • Non-API mode: asserts the response be_redirect and checks response.query_params["error"] == "unauthorized_client" (fragment-encoded for the token response type)
  • API mode: asserts HTTP 400, response_json_body["status"] == "redirect", and response_json_body["redirect_uri"] includes "error=unauthorized_client"

A CHANGELOG.md entry was also added (fixing the Changelog verifier failure).

@copilot hey, check why tests are failing and fix them

Done — see the reply above. Fixed in 009c5fa (test updates + CHANGELOG) and 80c3a89 (strengthened assertion).

@nbulaj nbulaj marked this pull request as ready for review April 24, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants