CVE-2026-18165: @fastify/oauth2 vulnerable to Login CSRF via plantable OAuth state cookies
@fastify/oauth2 is an OAuth 2.0 plugin for Fastify. In versions from 7.2.0 up to but not including 8.3.0, the plugin validates the OAuth state, and with PKCE the code verifier, by comparing the callback query parameter against an unprefixed, predictable cookie, with no server-side binding to the browser that began the flow. Any party able to write a cookie for the application's host, such as a sibling subdomain under the same registrable domain, can plant matching state and verifier cookies and complete an attacker-owned OAuth flow inside a victim's browser, silently signing the victim in to the attacker's account (login CSRF). It does not expose the victim's own account, credentials, or tokens. The issue is fixed in @fastify/oauth2 8.3.0, which adds an opt-in hostPrefixedCookies option. Users should upgrade to 8.3.0 and enable it, or bind state to a server-side session.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
@fastify/oauth2to a version that resolves this vulnerability.Fixed in 8.3.0 - Configuration
After upgrading to @fastify/oauth2 8.3.0, enable the opt-in hostPrefixedCookies option to prevent login CSRF via plantable OAuth state/verifier cookies.
@fastify/oauth2 hostPrefixedCookies = true
Event History
Frequently Asked Questions
What is the severity of CVE-2026-18165?
CVE-2026-18165 has a medium severity score of 4.2.
How do I fix CVE-2026-18165?
To fix CVE-2026-18165, upgrade the @fastify/oauth2 package to version 8.3.0 or later.
What type of vulnerability is CVE-2026-18165?
CVE-2026-18165 is classified as a Cross-Site Request Forgery (CSRF) vulnerability.
Which versions of @fastify/oauth2 are affected by CVE-2026-18165?
CVE-2026-18165 affects @fastify/oauth2 versions from 7.2.0 up to but not including 8.3.0.
What impact does CVE-2026-18165 have on applications?
CVE-2026-18165 can lead to unauthorized actions being performed on behalf of users due to vulnerable state cookies.