CVE-2023-31999

8.8 HIGH

📋 TL;DR

CVE-2023-31999 is a CSRF vulnerability in @fastify/oauth2 where a static state parameter was reused across all users and requests, allowing attackers to bypass OAuth2 CSRF protection. This affects all applications using vulnerable versions of @fastify/oauth2 for OAuth2 authentication. Attackers could potentially hijack user authentication flows.

💻 Affected Systems

Products:
  • @fastify/oauth2
Versions: All versions before v7.2.0
Operating Systems: All
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects applications using @fastify/oauth2 for OAuth2 authentication flows.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Attackers could hijack OAuth2 authentication flows to gain unauthorized access to user accounts, potentially leading to account takeover and data compromise.

🟠

Likely Case

Attackers could perform CSRF attacks against OAuth2 flows, potentially redirecting users to malicious sites or intercepting authentication tokens.

🟢

If Mitigated

With proper state parameter validation, OAuth2 flows remain secure against CSRF attacks as intended.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: LIKELY
Unauthenticated Exploit: ✅ No
Complexity: LOW

Exploitation requires the attacker to trick a user into initiating an OAuth2 flow, but the vulnerability makes CSRF protection ineffective.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: v7.2.0

Vendor Advisory: https://github.com/fastify/fastify-oauth2/releases/tag/v7.2.0

Restart Required: Yes

Instructions:

1. Update @fastify/oauth2 to version 7.2.0 or later using npm update @fastify/oauth2. 2. Review breaking changes in checkStateFunction. 3. Restart your application.

🔧 Temporary Workarounds

Implement custom state generation

all

Implement a custom checkStateFunction that generates unique state parameters per user session

🧯 If You Can't Patch

  • Implement additional CSRF protection mechanisms at the application level
  • Monitor OAuth2 authentication logs for suspicious patterns

🔍 How to Verify

Check if Vulnerable:

Check package.json for @fastify/oauth2 version. If version is below 7.2.0, you are vulnerable.

Check Version:

npm list @fastify/oauth2

Verify Fix Applied:

Verify @fastify/oauth2 version is 7.2.0 or higher and test OAuth2 flows with unique state parameters.

📡 Detection & Monitoring

Log Indicators:

  • Multiple OAuth2 requests with identical state parameters
  • OAuth2 callback requests with mismatched state parameters

Network Indicators:

  • OAuth2 authorization requests with predictable state parameters

SIEM Query:

source="oauth2" AND state="static_value" OR state_reuse=true

🔗 References

📤 Share & Export