CVE-2022-31142

7.5 HIGH

📋 TL;DR

This vulnerability in @fastify/bearer-auth allows attackers to perform timing attacks to estimate valid bearer token lengths, reducing the search space for brute force attacks. It affects users of @fastify/bearer-auth prior to versions 7.0.2 and 8.0.1, and fastify-bearer-auth versions 5.0.1 through 6.0.3. The vulnerability stems from insecure use of crypto.timingSafeEqual.

💻 Affected Systems

Products:
  • @fastify/bearer-auth
  • fastify-bearer-auth
Versions: @fastify/bearer-auth: <7.0.2, <8.0.1; fastify-bearer-auth: 5.0.1 through 6.0.3
Operating Systems: All
Default Config Vulnerable: ⚠️ Yes
Notes: All configurations using vulnerable versions are affected. The vulnerability exists in the authentication mechanism itself.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Attackers could eventually brute force valid bearer tokens, gaining unauthorized access to protected resources and potentially compromising user accounts or sensitive data.

🟠

Likely Case

Attackers could reduce brute force attack time by learning token length information, making token guessing more feasible over time.

🟢

If Mitigated

With proper network controls and monitoring, impact is limited to increased risk of token compromise rather than immediate breach.

🌐 Internet-Facing: HIGH
🏢 Internal Only: MEDIUM

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: MEDIUM

Timing attacks require multiple requests and statistical analysis, but tools exist to automate this. No public exploit code is known.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: @fastify/bearer-auth 7.0.2 or 8.0.1

Vendor Advisory: https://github.com/fastify/fastify-bearer-auth/security/advisories/GHSA-376v-xgjx-7mfr

Restart Required: Yes

Instructions:

1. Update package.json to use @fastify/bearer-auth version 7.0.2 or 8.0.1. 2. Run npm update @fastify/bearer-auth or yarn upgrade @fastify/bearer-auth. 3. Restart your Fastify application.

🔧 Temporary Workarounds

No known workarounds

all

The vulnerability is in the core authentication logic and cannot be mitigated without patching.

🧯 If You Can't Patch

  • Implement rate limiting on authentication endpoints to reduce timing attack effectiveness
  • Use additional authentication layers (IP whitelisting, WAF rules) to protect vulnerable endpoints

🔍 How to Verify

Check if Vulnerable:

Check package.json for @fastify/bearer-auth version <7.0.2 or <8.0.1, or fastify-bearer-auth version between 5.0.1 and 6.0.3

Check Version:

npm list @fastify/bearer-auth or npm list fastify-bearer-auth

Verify Fix Applied:

Verify package.json shows @fastify/bearer-auth version 7.0.2 or higher, or 8.0.1 or higher

📡 Detection & Monitoring

Log Indicators:

  • Multiple failed authentication attempts with varying token lengths
  • Unusual timing patterns in authentication requests

Network Indicators:

  • High volume of requests to authentication endpoints with incremental token variations

SIEM Query:

source="application_logs" AND (message="authentication failed" OR message="bearer token") | stats count by src_ip, token_length

🔗 References

📤 Share & Export