CVE-2022-31142: Fastify bearer auth Fastify-bearer-auth Vulnerable To Timing Attack Vulnerability

HIGH
Advisory Identifier: GHSA-376v-xgjx-7mfr
CVSS 7.5
CWE-203 CWE-208
Published
Advisory Summary

CVE-2022-31142 is a HIGH (CVSS 7.5) fastify-bearer-auth vulnerable to timing attack vulnerability (CWE-203: Observable Discrepancy) affecting Fastify bearer auth libraries in the npm ecosystem. The issue involves fastify-bearer-auth vulnerable to timing attack vector. Remediation is available by upgrading affected packages to version 7.0.2, 8.0.1.

CVE-2022-31142 at a Glance

CVE Identifier CVE-2022-31142
GHSA Identifier GHSA-376v-xgjx-7mfr
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-203: Observable Discrepancy
Affected Product Fastify bearer auth
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2022-31142

To remediate this vulnerability, upgrade all affected Fastify bearer auth dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

fastify-bearer-auth fixed: Latest secure release
npm install fastify-bearer-auth@Latest secure release
@fastify/bearer-auth fixed: 7.0.2
npm install @fastify/bearer-auth@7.0.2
@fastify/bearer-auth fixed: 8.0.1
npm install @fastify/bearer-auth@8.0.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls fastify-bearer-auth

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2022-31142, inspect your project dependencies using npm:

npm ls fastify-bearer-auth

Analyze the terminal output to locate any version of Fastify bearer auth in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 7.0.2), your application is affected.

Note: The npm ls fastify-bearer-auth command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-203: Observable Discrepancy, where the product behaves differently or sends different responses under different circumstances in a way that is observable to an unauthorized actor. In Fastify bearer auth, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact fastify-bearer-auth does not securely use crypto.timingSafeEqual. A malicious attacker could estimate the length of one valid bearer token. According to the corresponding RFC 6750, the bearer token has only base64 valid characters, reducing the range of characters for a brute force attack. All versions of fastify-bearer-auth are also affected. ### Patches We released: * v8.0.1 with a fix for the Fastify v4 line * v7.0.2 with a fix for the Fastify v3 line ### Workarounds There are no workarounds. Update your dependencies. ### References https://hackerone.com/reports/1633287 ### For more information If you have any questions or comments about this advisory: * Open an issue in [https://github.com/fastify/fastify-bearer-auth](https://github.com/fastify/fastify-bearer-auth) * Email us at [hello@matteocollina.com](mailto:hello@matteocollina.com)

CVE-2022-31142 Affected Fastify bearer auth Versions

3 component(s)
Fixed Versions:
7.0.28.0.1
Product / Package Ecosystem Affected Versions Fixed Version
fastify-bearer-auth
npm
≥ 5.0.1
≤ 6.0.3
@fastify/bearer-auth
npm
< 7.0.2
7.0.2
@fastify/bearer-auth
npm
≥ 8.0.0
< 8.0.1
All 1 versions
8.0.0
8.0.1

References

Frequently Asked Questions

What is CVE-2022-31142?
CVE-2022-31142 is a security vulnerability in Fastify bearer auth involving fastify-bearer-auth vulnerable to Timing Attack Vector under CWE-203: Observable Discrepancy.
Which Fastify bearer auth versions are affected?
Affected versions include releases prior to 7.0.2, 8.0.1 across affected packages: fastify-bearer-auth, @fastify/bearer-auth.
What version fixes CVE-2022-31142?
Upgrading to 7.0.2, 8.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is fastify-bearer-auth affected?
Yes, fastify-bearer-auth is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
Is @fastify/bearer-auth affected?
Yes, @fastify/bearer-auth is affected in releases prior to 7.0.2, 8.0.1. Upgrade your dependency to 7.0.2, 8.0.1 or later.
What is the CVSS score of CVE-2022-31142?
CVE-2022-31142 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2022-31142?
CVE-2022-31142 is classified under CWE-203: Observable Discrepancy (The product behaves differently or sends different responses under different circumstances in a way that is observable to an unauthorized actor.).
How can I check npm dependencies for CVE-2022-31142?
Run the dependency tree command: 'npm ls fastify-bearer-auth'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-376v-xgjx-7mfr",
  "modified" : "2022-07-21T15:57:26Z",
  "published" : "2022-07-15T19:14:27Z",
  "aliases" : [ "CVE-2022-31142" ],
  "summary" : "fastify-bearer-auth vulnerable to Timing Attack Vector",
  "details" : "### Impact\n\nfastify-bearer-auth does not securely use crypto.timingSafeEqual. A malicious attacker could estimate the length of one valid bearer token. According to the corresponding RFC 6750, the bearer token has only base64 valid characters, reducing the range of characters for a brute force attack.\n\nAll versions of fastify-bearer-auth are also affected.\n\n### Patches\n\nWe released:\n\n* v8.0.1 with a fix for the Fastify v4 line\n* v7.0.2 with a fix for the Fastify v3 line\n\n### Workarounds\n\nThere are no workarounds. Update your dependencies.\n\n### References\n\nhttps://hackerone.com/reports/1633287\n\n### For more information\nIf you have any questions or comments about this advisory:\n* Open an issue in [https://github.com/fastify/fastify-bearer-auth](https://github.com/fastify/fastify-bearer-auth)\n* Email us at [hello@matteocollina.com](mailto:hello@matteocollina.com)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "fastify-bearer-auth"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.1"
      }, {
        "last_affected" : "6.0.3"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/bearer-auth"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "7.0.2"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/bearer-auth"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.0.0"
      }, {
        "fixed" : "8.0.1"
      } ]
    } ],
    "versions" : [ "8.0.0" ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-bearer-auth/security/advisories/GHSA-376v-xgjx-7mfr"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-31142"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-bearer-auth/commit/0c468a616d7e56126dc468150f6a5a92e530b8e4"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-bearer-auth/commit/39353b15409ee99474545f615ffb16180cf3b716"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-bearer-auth/commit/f921a0582dc83112039004a9b5041141b50c5b3f"
  }, {
    "type" : "WEB",
    "url" : "https://hackerone.com/reports/1633287"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fastify/fastify-bearer-auth"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-203", "CWE-208" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-07-15T19:14:27Z",
    "nvd_published_at" : "2022-07-14T19:15:00Z"
  }
}