Skip to content

Commit 035e67b

Browse files
alex9smithBeryJu
authored andcommitted
sources/oauth: Make PKCE verifier 128 characters (#17763)
* sources/oauth: Make PKCE verifier 128 characters The PKCE spec requires the code verifier to be 43-128 characters inclusive[^1]. The default `length` argument to `generate_id` is 40 characters, which meant the verifier is always shorter than required by the spec. This could cause issues integrating authentik with PKCE-compliant OIDC providers. [^1]: https://datatracker.ietf.org/doc/html/rfc7636#section-4.1 * add length test Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens Langhammer <jens@goauthentik.io>
1 parent fdc3d95 commit 035e67b

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

authentik/sources/oauth/clients/oauth2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def get_redirect_args(self) -> dict[str, str]:
143143
if self.source.source_type.urls_customizable and self.source.pkce:
144144
pkce_mode = self.source.pkce
145145
if pkce_mode != PKCEMethod.NONE:
146-
verifier = generate_id()
146+
verifier = generate_id(length=128)
147147
self.request.session[SESSION_KEY_OAUTH_PKCE] = verifier
148148
# https://datatracker.ietf.org/doc/html/rfc7636#section-4.2
149149
if pkce_mode == PKCEMethod.PLAIN:

authentik/sources/oauth/tests/test_views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ def test_source_redirect_pkce(self):
205205
session = self.client.session
206206
state = session[f"oauth-client-{self.source.name}-request-state"]
207207
verifier = session[SESSION_KEY_OAUTH_PKCE]
208+
self.assertEqual(len(verifier), 128)
208209
challenge = pkce_s256_challenge(verifier)
209210

210211
self.assertEqual(qs["redirect_uri"], ["http://testserver/source/oauth/callback/test/"])

0 commit comments

Comments
 (0)