Fix Feide student verification - #4191
Merged
Merged
Conversation
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.
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withMismatchingStateError.Changes:
OAuthErrorfrom the token exchange (previously an uncaught 500).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