Skip to content

Fix Feide student verification - #4191

Merged
ch0rizo merged 4 commits into
masterfrom
fix-feide-oidc-validation
Aug 5, 2026
Merged

Fix Feide student verification#4191
ch0rizo merged 4 commits into
masterfrom
fix-feide-oidc-validation

Conversation

@ch0rizo

@ch0rizo ch0rizo commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

Feide student verification has been broken in production since mid-May (LEGO-10H).
The authlib 1.6 upgrade (#4143) started binding the OAuth state to the Django session, but the webapp calls the API cross-origin without cookies, so every /oidc/validate/ request failed with MismatchingStateError.

Changes:

  • Store the OAuth state in the oauth Redis cache keyed by user id + state, removing the session dependency while keeping the state single-use and bound to the authenticated user.
  • Verify the id_token (signature, claims, nonce) as authlib's wrapper previously did.
  • Consume the state atomically, and let a stale callback fail without destroying a pending flow.
  • Catch OAuthError from the token exchange (previously an uncaught 500).
  • Log state misses as warnings; fatal is reserved for real token validation failures, so LEGO-10H should flatline after deploy.

Testing

  • New integration test runs the real authlib client against a stubbed Feide (signed id_token + JWKS) with separate cookie-less clients, mirroring the browser. It fails on master and passes here.

  • New tests: replay, mismatching state, cross-user state, second-tab flows, wrong-nonce id_token, rejected authorization code.

  • Verified locally end to end with cookie-less requests

  • The code quality is at a minimum required level of quality, readability, and performance.

  • I have thoroughly tested my changes.

Please describe what and how the changes have been tested, and provide instructions to reproduce if necessary.

Dependent on frontend PR

Resolves #4190

ch0rizo added 3 commits August 5, 2026 00:35
authlib >= 1.6 binds the OAuth state to the Django session, but the
webapp calls the API cross-origin without cookies, so every validation
failed with MismatchingStateError. Store the state in the oauth cache
keyed by user id instead, and catch OAuthError from the token exchange
so rejected authorization codes return 400 instead of 500.
The earlier tests mocked the oauth client, so the authlib layer that
broke in the 1.6 upgrade was never exercised, and the test client's
cookie jar hid the session dependency. This test runs the real authlib
client against a stubbed Feide at the HTTP boundary and completes the
flow with separate cookie-less clients, failing on any implementation
that requires session state between authorize and validate.
Address review findings on the state rework: parse and verify the
id_token (signature, claims, nonce) as the removed authlib wrapper did,
key the cached state by user and state so concurrent flows do not
overwrite each other and stale callbacks cannot consume a pending flow,
consume the state atomically via the delete return value, log state
misses as warnings instead of fatals since they are routine user
behavior, and drop the dead PKCE plumbing. The integration test now
serves a real signed id_token with JWKS and asserts redirect_uri and
client authentication in the token exchange, plus rejection of a
wrong-nonce id_token.
@ch0rizo
ch0rizo requested a review from a team August 5, 2026 10:08
@ch0rizo ch0rizo self-assigned this Aug 5, 2026
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.92%. Comparing base (5f2135d) to head (6f4d492).

Files with missing lines Patch % Lines
lego/apps/users/views/oidc.py 91.66% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4191      +/-   ##
==========================================
+ Coverage   82.87%   82.92%   +0.05%     
==========================================
  Files         361      361              
  Lines       13100    13119      +19     
==========================================
+ Hits        10856    10879      +23     
+ Misses       2244     2240       -4     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ch0rizo
ch0rizo merged commit 3292bc3 into master Aug 5, 2026
5 checks passed
@ch0rizo
ch0rizo deleted the fix-feide-oidc-validation branch August 5, 2026 10:22
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.

Critical: broken feide student verification

1 participant