better-auth OAuth Redirect URI Scheme Validation Bypass (javascript: URI XSS via MCP Plugin)
First seen Aug 1, 2026 · Updated Aug 1, 2026 · CVSS 7.2
better-auth's OIDC provider and MCP plugin fail to validate the URI scheme of registered OAuth redirect_uris, allowing an attacker to register a javascript: URI that gets echoed back to the consent page. If the consent UI navigates to this URI unsafely, attacker JavaScript executes in the authorization server's origin, potentially hijacking victim sessions. This is a classic web input-validation flaw made newly relevant because it affects the auth layer underlying MCP server deployments, extending its blast radius to agent tool-authorization flows.
Technical Analysis
The vulnerability lies in the OAuth client registration endpoint, which accepts arbitrary redirect_uri values without enforcing an allowlist of safe schemes (e.g., https, custom app schemes) and rejecting dangerous ones like javascript:. Because the MCP plugin wraps the same underlying oidc-provider logic, any MCP server built on affected better-auth versions inherits this flaw. The attack requires the consent page to perform an unsafe client-side navigation (e.g., window.location.href = redirectURI) to the attacker-controlled URI, at which point the javascript: payload executes with the authorization server's origin privileges, giving the attacker access to session cookies, tokens, or the ability to silently approve consent on behalf of the victim. In an MCP context this could let an attacker impersonate a legitimate tool/client registration to hijack the OAuth flow an agent or user relies on to authorize MCP tool access, enabling downstream account takeover or unauthorized tool invocation.
Affected Systems
better-auth (oidc-provider plugin, mcp plugin); protocols: OAuth 2.0, OIDC, MCP
Detection Signatures
- Client registration requests where redirect_uri begins with 'javascript:', 'data:', or other non-http(s) schemes
- Consent response payloads containing an unescaped redirectURI matching a non-standard scheme
- Server-side logs showing OAuth client registrations with redirect_uri values lacking scheme validation
- Client-side code patterns using window.location.href or similar direct assignment from a server-returned redirect parameter without sanitization
Remediation Steps
- 1
Upgrade better-auth
Update to better-auth 1.6.13 or later (or a patched 1.7.0 release beyond beta.3) that enforces redirect_uri scheme validation.
- 2
Enforce redirect_uri allowlisting
Configure the OAuth/OIDC provider to only accept https:// (and approved custom app) schemes for redirect_uri during client registration, rejecting javascript:, data:, and vbscript: schemes.
- 3
Harden consent page navigation
Avoid directly assigning server-supplied redirect URIs to window.location.href; use safe redirect APIs, validate the URI scheme client-side as defense in depth, and consider server-side redirects instead of client-side navigation.
- 4
Audit MCP deployments
Identify all MCP servers using better-auth's oidc-provider or mcp plugin and confirm they are patched or have mitigating controls in place.
- 5
Session hardening
Use HttpOnly, Secure, and SameSite cookie attributes for session tokens to limit the impact of any successful script execution in the authorization server origin.
CVE / Advisory IDs
Industries Most Exposed
Respond to this threat
Pro subscribers get a full AI-generated incident-response playbook for this threat — detection, containment, eradication, and recovery steps — plus an unlimited AI Threat Advisor for questions about your environment.