Skip to content

providers/oauth2: use compare_digest for client_secret comparison#19979

Merged
BeryJu merged 2 commits intogoauthentik:mainfrom
kolega-ai-dev:v2-finding_37
Feb 3, 2026
Merged

providers/oauth2: use compare_digest for client_secret comparison#19979
BeryJu merged 2 commits intogoauthentik:mainfrom
kolega-ai-dev:v2-finding_37

Conversation

@kolega-ai-dev
Copy link
Contributor

@kolega-ai-dev kolega-ai-dev commented Feb 3, 2026

Vulnerability identified and fix provided by Kolega.dev

Location

authentik/providers/oauth2/views/token.py:166

Vulnerability

Line 166 uses '!=' for client secret comparison: 'self.provider.client_secret != self.client_secret'. This is a timing-unsafe comparison that could theoretically leak information about the secret through timing analysis. The codebase correctly uses hmac.compare_digest() elsewhere (authentication.py lines 37, 141, 150) for similar sensitive comparisons, demonstrating awareness of this issue. Additionally, utils.py line 209 has the same problem in authenticate_provider(). While practical exploitation requires many requests and precise timing measurements (making it difficult over network), this is a confirmed vulnerability that violates security best practices. The fix is trivial: import compare_digest from hmac and use 'not compare_digest(self.provider.client_secret, self.client_secret)'. Client secrets are 128-character random strings, making timing attacks harder but not impossible.

Fix

Replaced insecure '!=' comparisons with hmac.compare_digest() in both token.py and utils.py to prevent timing attacks on client secret validation. This matches the existing secure pattern already used in authentication.py throughout the codebase.

Replace insecure '!=' comparisons with hmac.compare_digest() to prevent
timing attacks on client secret validation. This matches the existing
security pattern used elsewhere in the codebase.
@kolega-ai-dev kolega-ai-dev requested a review from a team as a code owner February 3, 2026 15:50
@netlify
Copy link

netlify bot commented Feb 3, 2026

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit ef52976
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6982195d842085000809bbcd
😎 Deploy Preview https://deploy-preview-19979--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@BeryJu BeryJu reopened this Feb 3, 2026
@BeryJu BeryJu changed the title Insecure Client Secret Comparison Using Inequality Check providers/oauth2: use compare_digest for client_secret comparison Feb 3, 2026
@kolega-ai-dev
Copy link
Contributor Author

@BeryJu Apologies for the excessive open and closing of PRs! These should have still been in our fork but I fumbled the config!

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
@BeryJu
Copy link
Member

BeryJu commented Feb 3, 2026

@BeryJu Apologies for the excessive open and closing of PRs! These should have still been in our fork but I fumbled the config!

no worries, I'll re-open them one by one and update/test them before merging @kolega-ai-dev

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.21%. Comparing base (68f70a0) to head (49bc336).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19979      +/-   ##
==========================================
- Coverage   93.26%   93.21%   -0.06%     
==========================================
  Files         968      968              
  Lines       53389    53391       +2     
==========================================
- Hits        49794    49767      -27     
- Misses       3595     3624      +29     
Flag Coverage Δ
conformance 38.06% <75.00%> (+<0.01%) ⬆️
e2e 44.06% <75.00%> (+<0.01%) ⬆️
integration 22.86% <25.00%> (-0.05%) ⬇️
unit 91.41% <100.00%> (+<0.01%) ⬆️
unit-migrate 91.44% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BeryJu BeryJu added area:backend backport/version-2025.10 Add this label to PRs to backport changes to version-2025.10 backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12 labels Feb 3, 2026
@BeryJu BeryJu merged commit b32f33b into goauthentik:main Feb 3, 2026
103 checks passed
authentik-automation bot pushed a commit that referenced this pull request Feb 3, 2026
…9979)

* security: use constant-time comparison for client secrets

Replace insecure '!=' comparisons with hmac.compare_digest() to prevent
timing attacks on client secret validation. This matches the existing
security pattern used elsewhere in the codebase.

* format

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: kolega.dev <faizan@kolega.ai>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
BeryJu added a commit that referenced this pull request Feb 3, 2026
…erry-pick #19979 to version-2025.10) (#19982)

providers/oauth2: use compare_digest for client_secret comparison (#19979)

* security: use constant-time comparison for client secrets

Replace insecure '!=' comparisons with hmac.compare_digest() to prevent
timing attacks on client secret validation. This matches the existing
security pattern used elsewhere in the codebase.

* format



---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Kolega.dev <security@kolega.ai>
Co-authored-by: kolega.dev <faizan@kolega.ai>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
@BeryJu BeryJu added backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12 and removed backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12 labels Feb 3, 2026
authentik-automation bot pushed a commit that referenced this pull request Feb 3, 2026
…9979)

* security: use constant-time comparison for client secrets

Replace insecure '!=' comparisons with hmac.compare_digest() to prevent
timing attacks on client secret validation. This matches the existing
security pattern used elsewhere in the codebase.

* format

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: kolega.dev <faizan@kolega.ai>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
@authentik-automation
Copy link
Contributor

🍒 Cherry-pick to version-2025.12 created: #19987

BeryJu added a commit that referenced this pull request Feb 3, 2026
…erry-pick #19979 to version-2025.12) (#19987)

providers/oauth2: use compare_digest for client_secret comparison (#19979)

* security: use constant-time comparison for client secrets

Replace insecure '!=' comparisons with hmac.compare_digest() to prevent
timing attacks on client secret validation. This matches the existing
security pattern used elsewhere in the codebase.

* format



---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Kolega.dev <security@kolega.ai>
Co-authored-by: kolega.dev <faizan@kolega.ai>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
kensternberg-authentik added a commit that referenced this pull request Feb 4, 2026
* main: (26 commits)
  providers/saml: auto pull signature algorithm options (#17614)
  core, web: bump @isaacs/brace-expansion from 5.0.0 to 5.0.1 in /packages/prettier-config (#19990)
  web: bump @isaacs/brace-expansion from 5.0.0 to 5.0.1 in /web (#19989)
  stages/authenticator_webauthn: fix double JSON encoding of webauthn options (#19952)
  core: bump django from 5.2.10 to 5.2.11 (#19988)
  ci: allow setting assignee to fail (#19985)
  root: revert enterprise loading behaviour (#19485)
  web/flows: update flow background (#19974)
  providers/oauth2: use compare_digest for client_secret comparison (#19979)
  recovery: consume token in transaction (#19967)
  core: ask for token duration on recovery link/email by admin (#19875)
  core: bump aws-cdk-lib from 2.236.0 to 2.237.0 (#19958)
  web: bump the storybook group across 1 directory with 5 updates (#19960)
  core: bump library/nginx from `c881927` to `7fe5dda` in /website (#19961)
  core: bump gunicorn from 25.0.0 to 25.0.1 (#19959)
  core: bump goauthentik.io/api/v3 to 3.2026.2.0-rc1-1770129730 (#19973)
  lifecycle: bump shm size (#19369)
  crypto: Add ED25519 and ED448 support to the certificate builder (#19465)
  web/admin: Register stage elements. Fix linter warnings (#19948)
  web: bump knip from 5.82.1 to 5.83.0 in /web (#19962)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2025.10 Add this label to PRs to backport changes to version-2025.10 backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants