Skip to content

providers/oauth2: don't set state in responses if not supplied - #9735

Merged
jsachs merged 10 commits into
goauthentik:mainfrom
alxndrsn:minimal
Nov 5, 2026
Merged

jsachs merged 10 commits into
goauthentik:mainfrom
alxndrsn:minimal

Conversation

@alxndrsn

@alxndrsn alxndrsn commented May 15, 2024 •

Copy link
Copy Markdown
Contributor

I think this fixes a bug in OAuth2 / OpenID Connect (OIDC) implementation, as reported at getodk/central-backend#1135 (comment)

I guess this PR would ideally include tests which would fail without the code changes.

@alxndrsn
alxndrsn requested a review from a team as a code owner May 15, 2024 08:47
@netlify

netlify Bot commented May 15, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit be46401
🔍 Latest deploy log https://app.netlify.com/sites/authentik-docs/deploys/664476a1c032170008ffa32d
😎 Deploy Preview https://deploy-preview-9735--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 site configuration.

@netlify

netlify Bot commented May 15, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit be46401
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/664476a15427750008d241f1
😎 Deploy Preview https://deploy-preview-9735--authentik-storybook.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 site configuration.

@BeryJu

BeryJu commented May 15, 2024

Copy link
Copy Markdown
Member

Thanks for the PR! I'll have to do some reading but iirc as part of OIDC the state parameter is required? In that case we'd have to enforce it being set when the openid scope is set

@codecov

codecov Bot commented May 15, 2024 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.98%. Comparing base (edef75f) to head (44ba2cd).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9735      +/-   ##
==========================================
- Coverage   93.01%   92.98%   -0.03%     
==========================================
  Files        1230     1230              
  Lines       85771    85826      +55     
  Branches     4894     4894              
==========================================
+ Hits        79778    79806      +28     
- Misses       5906     5933      +27     
  Partials       87       87              
Flag Coverage Δ
conformance 30.43% <7.14%> (-0.02%) ⬇️
e2e 35.14% <5.71%> (-0.03%) ⬇️
integration 27.60% <0.00%> (-0.34%) ⬇️
rust 51.12% <ø> (ø)
unit 94.54% <100.00%> (+<0.01%) ⬆️
unit-migrate 94.55% <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 Harness.
📢 Have feedback on the report? Share it here.

@alxndrsn

Copy link
Copy Markdown
Contributor Author

iirc as part of OIDC the state parameter is required?

I may be reading the wrong place, but https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest reads:

state
RECOMMENDED. Opaque value used to maintain state between the request and the callback. Typically, Cross-Site Request Forgery (CSRF, XSRF) mitigation is done by cryptographically binding the value of this parameter with a browser cookie.

@lognaturel

Copy link
Copy Markdown

Hi! Any chance this would be a straightforward review for you @BeryJu or someone else given the spec clarification above? Thanks!

alxndrsn added a commit to getodk/central-backend that referenced this pull request Dec 5, 2024
* pass `next` value to IdP as `state`, with additional random prefix
* this makes the "next" value more trusted
* fix support for Authentik and other IdPs which do not support auth URLs without `state` (goauthentik/authentik#9735)
* may also improve support for IdPs which lack PKCE support (see: https://github.com/panva/openid-client/blob/1486c3a020af8d12449d1d6a4bdf4f2bf4d32b77/README.md#authorization-code-flow)

Closes #1134
Closes #1135
query_params = parse_qs(uri.query)
query_params["code"] = code.code
query_params["state"] = [str(self.params.state) if self.params.state else ""]
if self.params.state != None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would use is not None instead.

@netlify

netlify Bot commented Jul 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 67a9518
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a5af3393d31aa000868aebb
😎 Deploy Preview https://deploy-preview-9735--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.

jsachs and others added 2 commits November 3, 2026 12:40
…t supplied

Extend the fix to the form_post and implicit/hybrid responses, use the
same truthiness rule as AuthorizeError, and add tests for the code
(query, fragment, form_post) and implicit flows without state.

Co-Authored-By: Alex Anderson <[email protected]>
@jsachs
jsachs requested a review from a team as a code owner November 3, 2026 21:37
jsachs and others added 3 commits November 3, 2026 17:14
RFC 6749 §4.1.2/§4.2.2/§4.1.2.1 require returning the exact state value
whenever the parameter was present in the request, including when it is
empty. Check for presence (is not None) instead of truthiness in both
success and error responses, and keep blank values when re-parsing the
response URL for form_post and the ui_locales redirect rewrite.

Co-Authored-By: Alex Anderson <[email protected]>
@jsachs
jsachs removed the request for review from a team November 5, 2026 14:59
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in authentik Core Nov 5, 2026
@jsachs
jsachs enabled auto-merge (squash) November 5, 2026 15:01
@jsachs
jsachs disabled auto-merge November 5, 2026 15:30
@BeryJu BeryJu changed the title core/oauth2: don't set state in responses if not supplied providers/oauth2: don't set state in responses if not supplied Nov 5, 2026

@BeryJu BeryJu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally gravitated more towards not doing this and rather having a strict state requirement, but since the spec doesn't require state (and neither does OAuth 2.1 for that matter) I suppose it makes sense to merge this for compatibility

@jsachs
jsachs merged commit 9dd19ca into goauthentik:main Nov 5, 2026
163 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in authentik Core Nov 5, 2026
kensternberg-authentik added a commit that referenced this pull request Nov 5, 2026
…b-controller' into web/admin/breadcrumb-controller

* refs/remotes/origin/web/admin/breadcrumb-controller: (214 commits)
  The updated format for crumbs required an update to the unit tests.
  web/admin: Add a Breadcrumb context manager to the navigation suite
  Adding the Breadcrumbs visual component.
  Revised naming code to track certain features.
  web/elements: vendor sidebar and add icons (#27289)
  providers/oauth2: don't set state in responses if not supplied (#9735)
  web/elements: expansion visual hierarchy (#27562)
  providers/oauth2: accept ML-DSA keys for DPoP (#27174)
  website/docs: draft 2026.11 release notes (#26814)
  sources/ldap: store the directory date when resetting a password (#27578)
  events: bundle DB-IP Lite GeoIP databases instead of MaxMind GeoLite2 (#27102)
  web/admin: fix ldap source parent group form (#26421)
  stages/prompt: preserve empty initial values (#25148)
  core: batch expired cache and channel record cleanup (#27587)
  web: bump mermaid from 11.16.0 to 12.3.0 in /website (#27598)
  ci: bump taiki-e/install-action from 2.89.0 to 2.89.1 in /.github/actions/setup (#27630)
  core: bump goauthentik/fips-python from `d4c46c4` to `69e7058` in /lifecycle/container (#27626)
  ci: bump AndreKurait/docker-cache from 0.7.0 to 0.7.1 in /.github/actions/setup (#27628)
  ci: bump actions-rust-lang/setup-rust-toolchain from 2.0.0 to 2.0.1 in /.github/actions/setup (#27629)
  ci: bump actions-rust-lang/setup-rust-toolchain from 2.0.0 to 2.0.1 (#27627)
  ...
kensternberg-authentik added a commit that referenced this pull request Nov 5, 2026
…k-controller

* web/admin/breadcrumb-controller: (215 commits)
  Changes requested by reviewer (@GirlBossRush).
  The updated format for crumbs required an update to the unit tests.
  web/admin: Add a Breadcrumb context manager to the navigation suite
  Adding the Breadcrumbs visual component.
  Revised naming code to track certain features.
  web/elements: vendor sidebar and add icons (#27289)
  providers/oauth2: don't set state in responses if not supplied (#9735)
  web/elements: expansion visual hierarchy (#27562)
  providers/oauth2: accept ML-DSA keys for DPoP (#27174)
  website/docs: draft 2026.11 release notes (#26814)
  sources/ldap: store the directory date when resetting a password (#27578)
  events: bundle DB-IP Lite GeoIP databases instead of MaxMind GeoLite2 (#27102)
  web/admin: fix ldap source parent group form (#26421)
  stages/prompt: preserve empty initial values (#25148)
  core: batch expired cache and channel record cleanup (#27587)
  web: bump mermaid from 11.16.0 to 12.3.0 in /website (#27598)
  ci: bump taiki-e/install-action from 2.89.0 to 2.89.1 in /.github/actions/setup (#27630)
  core: bump goauthentik/fips-python from `d4c46c4` to `69e7058` in /lifecycle/container (#27626)
  ci: bump AndreKurait/docker-cache from 0.7.0 to 0.7.1 in /.github/actions/setup (#27628)
  ci: bump actions-rust-lang/setup-rust-toolchain from 2.0.0 to 2.0.1 in /.github/actions/setup (#27629)
  ...
@alxndrsn

alxndrsn commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@jsachs thanks for getting this over the line 🙏

I generally gravitated more towards not doing this

@BeryJu I'm intrigued - what were the arguments against making this change?

@alxndrsn
alxndrsn deleted the minimal branch November 6, 2026 05:26
@jsachs

jsachs commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

OAuth 2.1 also has mandatory PKCE, which doesn't get you 100% of the benefit of state but gets you most of the way there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants