← Back to Pull requests

[19.0][FIX] auth_oidc: rotate the PKCE code_verifier per authorization request #1057

Open
unknown opened this pull request with 618 lines diff across 7 files
View on GitHub
unknown unknown commented on Nov 01, 2026 14:56 UTC
Author

code_verifier is a stored Char field on auth.oauth.provider, generated once when the provider record is created and never rotated:

# models/auth_oauth_provider.py:41
code_verifier = fields.Char(
    default=lambda self: secrets.token_urlsafe(32), help="Used for PKCE."
)

It is read in two places that must agree — controllers/main.py builds the code_challenge from it, and models/res_users.py sends 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 query auth_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 state parameter.

# controllers/main.py, after super() has built the state
state = json.loads(params["state"])
params["state"] = json.dumps(pkce.remember(code_verifier, state))

# models/res_users.py, on the token request
code_verifier=pkce.claim(_state_from_params(params)),

Two changes are additive — no migration, no new dependency:

1. code_verifier becomes a non-stored compute field reading the session value.
2. list_providers() files the verifier in the session and tags the state after super(), 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:

  • A page lists providers more than once — auth_oauth.web_login() calls list_providers(), and get_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 with invalid_grant.

  • Two tabs starting SSO at the same time have the same problem.
  • Keying by a value carried in state fixes both, at the cost of a dict in the session (capped at 8 pending entries).

    Why the session

  • Per-user and per-browser, which is what "one verifier per authorization request" needs.

  • Survives the redirect round-trip — the browser carries the same session cookie to the IdP and back.

  • Nothing is persisted or cleaned up: an entry is dropped when claimed, and the session expires.
  • Two details

  • The compute returns "", never False. controllers/main.py calls .encode("ascii") on the value, so a boolean there raises AttributeError and takes the whole login page down with a 500. An empty verifier makes the token exchange fail at the provider instead — a controlled failure.

  • Tagging happens after super(). The state dict does not exist until the parent has built it.
  • Testing

    How I ran it: this branch's auth_oidc was 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_key fails 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

  • Session loss still breaks a login. If the session cookie is dropped between the authorize request and the callback, the verifier is gone and the exchange fails. That is inherent to not persisting it; persisting it would reintroduce the "readable in the database" problem this change removes. Happy to discuss a server-side store if you consider that trade-off wrong.

  • The verifier is no longer inspectable on the provider form. It was never meant to be configured by hand, so I removed the default rather than keeping a dead field.
  • ---

    🤖 Generated with Claude Code

    Diff: 618 lines (+463 / -155) across 7 files Reviewer: sbidoul Review duration: 42223m
    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
    0.73
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 44.2% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 73.4% (HIGH) · Higher = larger blast radius
    73.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.2% · Lower = rushed or shallow review
    44.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 41.0% · Moderate risk
    41.0%