@fastify/oauth2 is vulnerable to Cross-Site Request Forgery (CSRF)
42
Medium Risk
The plugin validates the OAuth state and, with PKCE, the code_verifier by comparing callback query parameters against cookies it set at the start of the flow. Those cookies use unprefixed, host-scoped names, so any party that can write a cookie for the application host can supply matching values, and the check only proves the query and cookie agree rather than that the same browser started the flow. A party controlling a sibling host under the registrable domain can plant both cookies and complete their own authorization flow inside a victim's browser, silently signing the victim into an account they control so subsequent activity is recorded against it. The fix ships an opt-in hostPrefixedCookies flag that switches the state and verifier cookies to __Host- prefixed names browsers refuse from a related host, safely rejects invalid signed cookies instead of falling back to raw values, and clears the state and verifier cookies after callback processing to prevent replay.
You are affected if you are using a version that falls within the vulnerable range, use @fastify/oauth2 for OAuth login with the built-in state validation (the default checkStateFunction, not a server-side session binding), and another host under the same registrable domain can set cookies for your application (for example an untrusted or forgotten subdomain, a dangling DNS record, or the same host over plaintext HTTP).
@fastify/oauth2 is vulnerable to Cross-Site Request Forgery (CSRF) in versions 7.2.0 - 8.2.1.
Upgrade the @fastify/oauth2 library to the patch version and enable hostPrefixedCookies: true (HTTPS required), or set __Host- prefixed cookie names with secure: true and path: '/'. Alternatively, bind state to a server-side session with generateStateFunction and checkStateFunction.
Connect your repositories to instantly see whether vulnerable or malicious packages exist in your codebase.
Free. No credit card required.

I consent to receiving marketing communications based on Aikido’s Privacy Policy.
SOC 2Compliant
ISO 27001Compliant