[19.0][FIX] auth_oidc: rotate the PKCE code_verifier per authorization request #1057
All Vouch review confidence checks passed
Residual risk 0.41 = Change Risk (0.73) × (1 − Review Confidence (0.44)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.73 · 618 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.385
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.073
Real PR Conversation Timeline
1 comments
"Review active on #1057"
general
weight: 0.35
sbidoul
code_verifieris a storedCharfield onauth.oauth.provider, generated once when the provider record is created and never rotated:It is read in two places that must agree —
controllers/main.pybuilds thecode_challengefrom it, andmodels/res_users.pysends it back on the token request. Because the value lives on the provider record, every user in the realm shares one verifier, across all concurrent logins, for the entire lifetime of the provider. It also sits in a database table readable by anyone who can queryauth_oauth_provider.RFC 7636 §5.1 asks for a fresh, unpredictable verifier per authorization request. The protection PKCE gives comes from an attacker who captures an authorization code being unable to supply the matching verifier — a single shared value removes that.
Approach
Keep the verifier out of the database and out of the provider record: generate it per request, keep it in the session, and key it by a random identifier carried in the OAuth
stateparameter.Two changes are additive — no migration, no new dependency:
1.
code_verifierbecomes a non-stored compute field reading the session value.2.
list_providers()files the verifier in the session and tags the state aftersuper(), so the challenge and the filed verifier are always the same value.Why keyed rather than a single session slot
My first attempt used one session key. It is wrong, and worth explaining because it is not obvious:
auth_oauth.web_login()callslist_providers(), andget_auth_signup_qcontext()calls it again. A single slot means the second render overwrites the first one's verifier, and the links rendered from the first call fail withinvalid_grant.Keying by a value carried in
statefixes both, at the cost of a dict in the session (capped at 8 pending entries).Why the session
Two details
"", neverFalse.controllers/main.pycalls.encode("ascii")on the value, so a boolean there raisesAttributeErrorand takes the whole login page down with a 500. An empty verifier makes the token exchange fail at the provider instead — a controlled failure.super(). The state dict does not exist until the parent has built it.Testing
How I ran it: this branch's
auth_oidcwas copied into an existing Odoo 20.0 deployment (only the manifest version was adjusted) and the module's own test suite was run with--test-tags=/auth_oidc. The code under test is exactly this branch's; the runtime being 20.0 rather than 19.0 is the one difference, and the touched APIs are unchanged between them.| Scenario | Result |
|---|---|
| Verifier rotates between requests | PASS |
| Two renders of the same page agree on challenge and state | PASS |
| Two concurrent authorizations each keep their verifier | PASS |
| Callback sends the verifier filed for its state | PASS |
| Callback with no filed verifier (pre-upgrade session) sends an empty one, no crash | PASS |
| Existing auth-code login tests (8) | PASS |
| Existing implicit-flow / JWKS tests | PASS — untouched,
flow == "access_token"never reaches this code |test_login_without_any_keyfails on this branch both before and after this change (it asserts on a captured log record,0 != 1); it is unrelated and I left it alone.I have not tested: multi-provider setups where one provider uses PKCE and another does not, and session backends other than the default filesystem store.
Trade-offs
defaultrather than keeping a dead field.---
🤖 Generated with Claude Code