doorkeeper 5.9.9 → 5.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c4d0c4d775062d003452c97290c5fb4308812e17590946b9f8db9922e40f9d7
4
- data.tar.gz: 7af434e11413a59e94cf12edd6ddcb088940110fabbd1174f0bacb2869a254da
3
+ metadata.gz: ae65c27ea97993e75b392f0521e7356d85a55a174b6170127a9334b640c90116
4
+ data.tar.gz: f3bab7926aaceff3070be754355b9bfa8ac52bc3e7377dd59fa6139a16ea2c03
5
5
  SHA512:
6
- metadata.gz: 1029aa2d0ff981b3d114f656f5b8d17308a946edd9466e7fe93d93fa5b6d1ba3c6873ba6cf628eab86ccb2f50b14507f272d61a0af829f2184963908941bb91c
7
- data.tar.gz: 5b474f0a07ba2785acdbadca5d874a0b9e50955bebd0318499f84710cb06b0d1e8d58419ac4b889045e504011ddc88398ffea0c345434df291f0b43cf60fb3d2
6
+ metadata.gz: 20a1d98eccb89abb168f664df13904bbb2b2dde28b29e0c72cce005f0259a2b52d39bb864f5e1f9abcd2608405e162c28e21c2beb387ee5ff4a47578c477fc69
7
+ data.tar.gz: 9904219cc5b1db3920aabc2a0719419432cb0b22db3b3d7d7613de69b13afb595a99eceef8182f21936086b4484a60587e55c0013c4bf9d58fdc9e064dce934d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ upgrade guides.
5
5
 
6
6
  User-visible changes worth mentioning.
7
7
 
8
+ ## 5.9.10
9
+
10
+ - Fix: `force_pkce` without the PKCE columns (`rails generate doorkeeper:pkce`) no longer accepts any `code_verifier` from a non-confidential client. The authorization code flow is now refused with `server_error` for those clients until the migration is applied.
11
+ - [GHSA-88xh-fgq2-m396] Fix: with refresh tokens revoked on use, exchanging a refresh token now ends the transition period of the one it replaced. Before, a replaced refresh token stayed usable until the newer access token passed through `doorkeeper_authorize!`, so a client that refreshed twice in a row, or a resource server that checks tokens another way (`by_token`, introspection), left old refresh tokens of the chain valid.
12
+ - Fix: refuse the client credentials grant for public (non-confidential) clients with `unauthorized_client`, as RFC 6749 Section 4.4 limits it to confidential clients: a public client's `client_id` alone was enough to be issued a token. Set `allow_client_credentials_grant_for_public_clients true` to keep the old behavior.
13
+
8
14
  ## 5.9.9
9
15
 
10
16
  - Fix: `AuthorizedApplicationsController` now answers `401 Unauthorized` instead of running with a `nil` resource owner, which listed and revoked every token that has no resource owner — the ones the client credentials flow issues. Affected host applications are those whose `resource_owner_authenticator` answers `nil` without halting the request itself; the generated initializer's example redirects and is not affected.
@@ -298,6 +298,16 @@ module Doorkeeper
298
298
  option :skip_client_authentication_for_password_grant,
299
299
  default: false
300
300
 
301
+ # Issue client credentials tokens to public (non-confidential) clients as well.
302
+ #
303
+ # This is discouraged. RFC 6749 Section 4.4 limits the client credentials grant
304
+ # to confidential clients: a public client is known by its client_id alone, so
305
+ # anyone who knows that id is issued a token in the name of the application.
306
+ # Off by default, in which case such a request is answered with
307
+ # :unauthorized_client.
308
+ option :allow_client_credentials_grant_for_public_clients,
309
+ default: false
310
+
301
311
  # Hook to allow arbitrary user-client authorization
302
312
  option :authorize_resource_owner_for_client,
303
313
  default: ->(_client, _resource_owner) { true }
@@ -323,6 +333,10 @@ module Doorkeeper
323
333
  # In case this option invocation result is `false`, Doorkeeper server returns
324
334
  # :unauthorized_client error and stops the request.
325
335
  #
336
+ # A public (non-confidential) application is refused the client credentials
337
+ # grant without the block being asked, unless
338
+ # +allow_client_credentials_grant_for_public_clients+ is set.
339
+ #
326
340
  # @param allow_grant_flow_for_client [Proc] Block or any object respond to #call
327
341
  # @return [Boolean] `true` if allow or `false` if forbid the request
328
342
  #
@@ -701,6 +715,8 @@ module Doorkeeper
701
715
  end
702
716
 
703
717
  def allow_grant_flow_for_client?(grant_flow, client)
718
+ # The client credentials grant is for confidential clients only (RFC 6749 §4.4).
719
+ return false if grant_flow == OAuth::CLIENT_CREDENTIALS && !client_credentials_grant_open_to?(client)
704
720
  return true unless option_defined?(:allow_grant_flow_for_client)
705
721
 
706
722
  allow_grant_flow_for_client.call(grant_flow, client)
@@ -712,6 +728,12 @@ module Doorkeeper
712
728
 
713
729
  private
714
730
 
731
+ # An application that does not say it is confidential is taken for a public one.
732
+ def client_credentials_grant_open_to?(client)
733
+ allow_client_credentials_grant_for_public_clients ||
734
+ (client.respond_to?(:confidential?) && client.confidential?)
735
+ end
736
+
715
737
  # Helper to read boolearized configuration option
716
738
  def option_set?(instance_key)
717
739
  var = instance_variable_get("@#{instance_key}")
@@ -8,6 +8,9 @@ module Doorkeeper
8
8
  validate :grant, error: Errors::InvalidGrant
9
9
  # @see https://datatracker.ietf.org/doc/html/rfc6749#section-5.2
10
10
  validate :redirect_uri, error: Errors::InvalidGrant
11
+ # Runs before :code_verifier, which has nothing to verify against when
12
+ # the PKCE columns are missing.
13
+ validate :pkce_storage, error: Errors::ServerError
11
14
  validate :code_verifier, error: Errors::InvalidGrant
12
15
 
13
16
  attr_reader :grant, :client, :redirect_uri, :access_token, :code_verifier,
@@ -90,6 +93,25 @@ module Doorkeeper
90
93
  )
91
94
  end
92
95
 
96
+ # With force_pkce the code_verifier of a non-confidential client must be
97
+ # checked against the challenge stored on the grant. Without the columns
98
+ # the doorkeeper:pkce generator adds there is no stored challenge, and
99
+ # #validate_code_verifier would accept any verifier. Refuse the exchange
100
+ # with server_error instead (see PreAuthorization#validate_pkce_storage,
101
+ # which stops such a code from being issued in the first place).
102
+ def validate_pkce_storage
103
+ return true unless Doorkeeper.config.force_pkce?
104
+ return true if client.confidential
105
+ return true if pkce_supported?
106
+
107
+ ::Rails.logger.error(
108
+ "[DOORKEEPER] force_pkce is enabled but the PKCE columns are missing from the " \
109
+ "oauth_access_grants table, so authorization codes cannot be exchanged. " \
110
+ "Run `rails generate doorkeeper:pkce` and apply the migration.",
111
+ )
112
+ false
113
+ end
114
+
93
115
  # if either side (server or client) request PKCE, check the verifier
94
116
  # against the DB - if PKCE is supported
95
117
  def validate_code_verifier
@@ -24,6 +24,11 @@ module Doorkeeper
24
24
  validate :scopes, error: Errors::InvalidScope
25
25
  validate :code_challenge, error: Errors::InvalidRequest
26
26
  validate :code_challenge_method, error: Errors::InvalidCodeChallengeMethod
27
+ # Runs after :code_challenge so a missing challenge is still answered as
28
+ # the client's error. The method is not: without the columns no method is
29
+ # supported (#validate_code_challenge_method skips the check), so an
30
+ # unknown one is answered with server_error like a known one.
31
+ validate :pkce_storage, error: Errors::ServerError
27
32
 
28
33
  attr_reader :client, :code_challenge, :code_challenge_method, :missing_param,
29
34
  :redirect_uri, :resource_owner, :response_type, :state,
@@ -188,6 +193,32 @@ module Doorkeeper
188
193
  (code_challenge_method.present? && Doorkeeper.config.pkce_code_challenge_methods_supported.include?(code_challenge_method))
189
194
  end
190
195
 
196
+ # force_pkce promises that every authorization code issued to a
197
+ # non-confidential client is bound to a code_challenge, but the columns
198
+ # that hold the challenge come from the separate doorkeeper:pkce
199
+ # generator. Without them Authorization::Code drops the challenge and
200
+ # the token endpoint has nothing to check the code_verifier against, so
201
+ # the code would be exchangeable with any verifier while the server
202
+ # appears to enforce PKCE. That is a server misconfiguration: refuse to
203
+ # issue the code and answer server_error (RFC 6749 Section 4.1.2.1).
204
+ #
205
+ # Only response types that issue a code are refused. Without force_pkce
206
+ # nothing changes: PKCE is then opportunistic and a challenge is ignored
207
+ # when it cannot be stored.
208
+ def validate_pkce_storage
209
+ return true unless Doorkeeper.config.force_pkce?
210
+ return true if client.confidential
211
+ return true unless response_type.to_s.split.include?("code")
212
+ return true if Doorkeeper.config.access_grant_model.pkce_supported?
213
+
214
+ ::Rails.logger.error(
215
+ "[DOORKEEPER] force_pkce is enabled but the PKCE columns are missing from the " \
216
+ "oauth_access_grants table, so authorization codes cannot be issued. " \
217
+ "Run `rails generate doorkeeper:pkce` and apply the migration.",
218
+ )
219
+ false
220
+ end
221
+
191
222
  def response_on_fragment?
192
223
  return response_type == "token" if response_mode.nil?
193
224
 
@@ -38,6 +38,9 @@ module Doorkeeper
38
38
  # transition period, after which the old refresh token will be revoked.
39
39
  raise Errors::InvalidGrantReuse if refresh_token.revoked?
40
40
 
41
+ # Presenting this refresh token proves the client received it, so
42
+ # the transition period of the one it replaced is over.
43
+ refresh_token.revoke_previous_refresh_token!
41
44
  create_access_token
42
45
  else
43
46
  # Use locking when refresh tokens are revoked immediately
@@ -5,7 +5,7 @@ module Doorkeeper
5
5
  # Semantic versioning
6
6
  MAJOR = 5
7
7
  MINOR = 9
8
- TINY = 9
8
+ TINY = 10
9
9
  PRE = nil
10
10
 
11
11
  # Full version number
@@ -182,6 +182,14 @@ Doorkeeper.configure do
182
182
  #
183
183
  # revoke_previous_client_credentials_token
184
184
 
185
+ # Issue client credentials tokens to public (non-confidential) applications as
186
+ # well. Not recommended: RFC 6749 Section 4.4 limits the grant to confidential
187
+ # clients, as a public client is known by its client_id alone and anyone who
188
+ # knows that id would get a token in the name of the application. By default
189
+ # such a request is refused with unauthorized_client.
190
+ #
191
+ # allow_client_credentials_grant_for_public_clients true
192
+
185
193
  # Only allow one valid access token obtained via authorization code
186
194
  # per client. If a new access token is obtained before the old one
187
195
  # expired, the old one gets revoked (disabled by default)
@@ -191,6 +199,10 @@ Doorkeeper.configure do
191
199
  # Require non-confidential clients to use PKCE when using an authorization code
192
200
  # to obtain an access_token (disabled by default)
193
201
  #
202
+ # Needs the PKCE columns on the access grants table: run
203
+ # `rails generate doorkeeper:pkce` and migrate first. Without them the
204
+ # authorization code flow is refused with a `server_error` for those clients.
205
+ #
194
206
  # force_pkce
195
207
 
196
208
  # Hash access and refresh tokens before persisting them.
@@ -416,6 +428,10 @@ Doorkeeper.configure do
416
428
  # In case this option invocation result is `false`, Doorkeeper server returns
417
429
  # :unauthorized_client error and stops the request.
418
430
  #
431
+ # A public (non-confidential) application is refused the client credentials
432
+ # grant without the block being asked, unless
433
+ # allow_client_credentials_grant_for_public_clients is set.
434
+ #
419
435
  # @param allow_grant_flow_for_client [Proc] Block or any object respond to #call
420
436
  # @return [Boolean] `true` if allow or `false` if forbid the request
421
437
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.9.9
4
+ version: 5.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Elias Philipp
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2026-09-24 00:00:00.000000000 Z
14
+ date: 2026-11-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties