Summary
Better Auth's legacy OIDC and MCP plugins implement refresh token grants that do not verify the confidential client's client_secret, authenticating only by refresh token and client_id.
An attacker who obtains a valid refresh_token can continuously mint new access tokens and rotated refresh tokens via exposed token endpoints, bypassing client authentication requirements.
Affected context
This vulnerability arises in applications that integrate Better Auth's legacy oidcProvider or mcp plugins to expose OAuth-style token endpoints such as:
/api/auth/oauth2/token/api/auth/mcp/token
It is relevant when:
- Confidential OAuth/OIDC clients are expected to authenticate with a client_secret, and
- Refresh tokens issued by these flows can be obtained or intercepted through other weaknesses, logging, or misuse.
The issue does not affect the @better-auth/oauth-provider package but specifically impacts deployments using the legacy plugin-based token endpoints.
Exploit preconditions
- Attack surface: Public or semi-public OAuth token endpoints (
/api/auth/oauth2/token,/api/auth/mcp/token) reachable over HTTP(S). - Required access: Possession of any valid refresh_token and knowledge of the associated client_id (e.g., from application configuration or prior traffic).
- Trigger point: Submitting a refresh_token grant request to the token endpoint, where the server fails to enforce client_secret verification for confidential clients.
- Why exploitation is possible: The implementation binds refresh tokens only to a database row and client_id, and treats these as sufficient proof of client identity, omitting the client_secret check required for confidential clients under OAuth 2.0.
Why this happens
The core issue is an authentication bypass in the refresh token grant logic.
In OAuth 2.0, confidential clients must authenticate using a client_secret (or equivalent mechanism) when exchanging refresh tokens, ensuring that possession of a refresh token alone does not fully represent the client identity. In the affected Better Auth plugins, the refresh token processing logic validates only:
- That the submitted refresh_token corresponds to an existing record, and
- That the submitted client_id matches the record.
By not requiring a valid client_secret for confidential clients, the system effectively treats the refresh token as the sole credential. This maps to:
- CWE-287 (Improper Authentication): The system does not sufficiently verify the identity of the client in the refresh flow.
- CWE-306 (Missing Authentication for Critical Function): Token minting and refresh rotation functions are exposed without appropriate client authentication.
- CWE-345 (Insufficient Verification of Data Authenticity): The authenticity of the client is inferred from weak or incomplete checks.
- CWE-863 (Incorrect Authorization): The service authorizes issuing new tokens to entities that have not fully authenticated as the intended confidential client.
Abstractly, this is a pattern where a long-lived credential (refresh token) is treated as both an authorization artifact and an authentication credential, violating separation of duties and weakening client assurance guarantees.
Potential impact
- An attacker with any valid refresh_token may continuously mint new access tokens for the associated user session.
- An attacker can obtain rotated refresh tokens, extending their unauthorized access indefinitely as long as the flow remains unrevoked.
- Compromise of a single refresh token could lead to full account takeover for the user associated with that token.
- Attackers may bypass client-side security assumptions, impersonating confidential clients without possessing their client_secret.
- In multi-tenant or multi-client deployments, attackers might escalate privileges by using stolen refresh tokens from more privileged clients.
General mitigation guidance
Effective mitigation focuses on restoring strong client authentication semantics and hardening token lifecycle management:
- Enforce client authentication:
- Design refresh token handling so confidential clients must prove their identity using a client_secret or equivalent credential for every token exchange.
- Treat the client_secret as a primary authentication factor separate from the refresh token, not as optional metadata.
- Constrain refresh tokens:
- Bind refresh tokens to specific clients, audiences, and use contexts, rejecting tokens presented by mismatched clients.
- Limit refresh token lifetime and scope, and consider rotation patterns that invalidate old tokens once exchanged.
- Harden token storage and access:
- Store refresh tokens in locations that are not accessible to untrusted code paths (e.g., avoid logging, browser storage patterns that allow exfiltration).
- Apply least privilege to services or microservices that can read or manipulate token records.
- Apply secure defaults:
- Default to treating OAuth clients as confidential when they can hold secrets, and require explicit configuration to use public client flows.
- Fail closed if client authentication information is missing, malformed, or inconsistent with stored metadata.
These measures collectively reduce the risk that possession of a refresh token alone is enough to impersonate a client or user.
How teams detect issues like this
Detection can center on both design-time and runtime signals:
- Static and code review checks:
- Review token endpoint implementations to ensure refresh token grants include verification of client_secret (or equivalent) for confidential clients.
- Look for conditional branches where client authentication is skipped or treated as optional, especially for legacy or plugin-based flows.
- Use static analysis rules or linters to flag token issuance paths that do not involve any client credential checks.
- Configuration and policy enforcement:
- Maintain a registry of OAuth/OIDC clients with explicit flags for public vs. confidential, and enforce policies that require authentication for confidential clients at all token endpoints.
- Implement CI/CD checks that validate configuration consistency (e.g., no token endpoint can mint tokens for a confidential client without specified auth requirements).
- Runtime monitoring:
- Instrument token endpoints to log metadata about refresh token grants, including whether client authentication was performed and from which IP or environment.
- Set alerts for anomalous patterns, such as repeated refresh token grants from unexpected networks or clients without corresponding client_secret validation.
Automated security tooling, including application security testing platforms and specialized OAuth security analyzers, can help identify flows where refresh tokens are accepted without proper client authentication.

