Summary
Pocket ID's OIDC token endpoint previously validated authorization codes incorrectly, rejecting them only when both the client ID was wrong and the code was expired.
Under these conditions, attackers could perform cross-client code exchange and reuse expired authorization codes, potentially gaining tokens for clients they do not control.
Affected context
This vulnerability affects deployments of Pocket ID acting as an OpenID Connect (OIDC) provider where the token endpoint:
- Accepts authorization codes issued to one client and allows their exchange by a different client
- Fails to strictly validate both the binding between authorization code and client, and the expiration status independently
- Operates in environments where multiple relying parties (OIDC clients) share the same Pocket ID instance
The risk is more pronounced where authorization codes are transmitted or stored in ways that could be observed or intercepted by another client or intermediary.
Exploit preconditions
- Attack surface: OIDC token endpoint exposed to OIDC clients (usually over HTTPS).
- Required access: Ability to act as, or control, a registered OIDC client that can call the token endpoint; ability to obtain or intercept an authorization code issued to a different client, or access to codes that should be expired.
- Trigger point: Submitting a token request with:
- A valid (or not-yet-rejected) authorization code, but using a different
client_idthan the one to which the code was originally issued, and/or - A code that should be expired but is accepted due to the flawed combined condition.
- Why exploitation is possible: The server enforces rejection only when both the client ID is incorrect and the code is expired, instead of independently rejecting on either condition. This breaks the strict binding between authorization codes, clients, and lifetimes required by the OIDC authorization code flow.
Why this happens
The core issue stems from improper authorization logic at the token endpoint, aligning with CWE-863: Incorrect Authorization.
Instead of enforcing separate checks (reject if the client ID does not match the code's original client; reject if the code is expired), the implementation effectively used a logical conjunction, leading to acceptance when only one of these conditions was violated.
This pattern reflects an incorrect enforcement of security policy, where authorization decisions depend on multiple conditions but are combined improperly, weakening the guarantees of the OIDC authorization code flow and breaking the assumption that codes are single-use, client-bound, and time-limited.
Potential impact
- An attacker-controlled client could exchange an authorization code originally issued to a different client, potentially obtaining tokens intended for another relying party.
- Reuse of authorization codes that should have expired, extending the effective window of attack for intercepted or leaked codes.
- Impersonation of end users at a different client application, depending on how the obtained tokens are trusted and used.
- Elevation of privileges within relying party applications that trust the OIDC tokens for session establishment or authorization.
- Undermining of security controls relying on strict code lifetimes and single-use semantics in the OIDC authorization code flow.
General mitigation guidance
Effective mitigation focuses on correcting the authorization checks around the OIDC token endpoint and reinforcing protocol invariants:
- Ensure authorization codes are strictly bound to a single client: verify that the
client_idpresenting the code matches the client recorded when the code was issued, and reject immediately on mismatch. - Enforce code expiration independently: verify that each code has not expired at the time of exchange, and reject if it is no longer valid, regardless of client identity.
- Treat authorization codes as single-use tokens: mark codes as consumed on first successful exchange and reject any subsequent attempts to reuse them.
- Implement clear, centralized authorization logic for token issuance, avoiding complex or ambiguous condition combinations that are hard to reason about.
- Minimize code lifetime and implement conservative default timeouts, reducing the useful window for any intercepted codes.
- Apply the principle of least privilege to tokens: only issue scopes and claims necessary for the relying party to function, limiting impact if misuse occurs.
How teams detect issues like this
Detection can center on both code-level analysis and runtime monitoring:
- Static analysis & code review:
- Inspect token endpoint logic for conditional checks around authorization codes, ensuring independent validation of client binding, expiration, and single-use semantics.
- Look for any combined conditions (e.g., logical ANDs) where rejection should occur if any of several validations fail.
- Verify that authorization code records in storage include client association, expiry, and a used/consumed flag, and that all are enforced.
- Automated testing:
- Create integration tests that attempt to exchange a code with a different
client_idthan the original, expecting rejection. - Test reuse of a previously consumed or expired code, ensuring the token endpoint returns errors consistently.
- Runtime monitoring:
- Log token endpoint requests with anonymized indicators showing relationships between
client_id, code IDs, and usage counts; alert on multiple clients attempting to redeem the same code or on repeated code usage. - Monitor for anomalies where authorization codes are successfully exchanged long after their expected lifetime.
- Security tooling:
- Use protocol-aware security tests or OIDC conformance suites that specifically validate authorization code binding and expiry behavior.

