CVE-2023-27495: @fastify/csrf protection Bypass Of CSRF Protection Vulnerability

MODERATE
Advisory Identifier: GHSA-qrgf-9gpc-vrxw
CVSS 5.3
CWE-352
Published
Advisory Summary

CVE-2023-27495 is a MODERATE (CVSS 5.3) bypass of csrf protection vulnerability (CWE-352: Cross-Site Request Forgery (CSRF)) affecting @fastify/csrf protection libraries in the npm ecosystem. The issue involves bypass of csrf protection in the presence of predictable userinfo. Remediation is available by upgrading affected packages to version 4.1.0, 6.3.0.

CVE-2023-27495 at a Glance

CVE Identifier CVE-2023-27495
GHSA Identifier GHSA-qrgf-9gpc-vrxw
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-352: Cross-Site Request Forgery (CSRF)
Affected Product @fastify/csrf protection
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.3

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

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

How to Fix CVE-2023-27495

To remediate this vulnerability, upgrade all affected @fastify/csrf protection 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/csrf-protection fixed: 4.1.0
npm install @fastify/csrf-protection@4.1.0
@fastify/csrf-protection fixed: 6.3.0
npm install @fastify/csrf-protection@6.3.0
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/csrf-protection

How to Check if You Are Affected

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

npm ls @fastify/csrf-protection

Analyze the terminal output to locate any version of @fastify/csrf protection in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.1.0), your application is affected.

Note: The npm ls @fastify/csrf-protection 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-352: Cross-Site Request Forgery (CSRF), where the web application does not, or cannot, sufficiently verify whether a request was intentionally provided by the user who sent the request, which could have originated from an unauthorized actor. In @fastify/csrf protection, 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

## Description The [CSRF](https://owasp.org/www-community/attacks/csrf) protection enforced by the `@fastify/csrf-protection` library in combination with `@fastify/cookie` can be bypassed from network and same-site attackers under certain conditions. `@fastify/csrf-protection` supports an optional `userInfo` parameter that binds the CSRF token to the user. This parameter has been introduced to prevent cookie-tossing attacks as a fix for [CVE-2021-29624](https://www.cvedetails.com/cve/CVE-2021-29624). Whenever `userInfo` parameter is missing, or its value can be predicted for the target user account, network and [same-site](https://canitakeyoursubdomain.name/) attackers can 1. fixate a `_csrf` cookie in the victim's browser, and 2. forge CSRF tokens that are valid for the victim's session. This allows attackers to bypass the CSRF protection mechanism. As a fix, `@fastify/csrf-protection` starting from version 6.3.0 (and v4.1.0) includes a server-defined secret `hmacKey` that cryptographically binds the CSRF token to the value of the `_csrf` cookie and the `userInfo` parameter, making tokens non-spoofable by attackers. This protection is effective as long as the `userInfo` parameter is unique for each user. ### Patches This is patched in version 6.3.0 and v4.1.0. ### Workarounds As a workaround, developers can use a random, non-predictable `userInfo` parameter for each user. ## Credits * Pedro Adão (@pedromigueladao), [Instituto Superior Técnico, University of Lisbon](https://tecnico.ulisboa.pt/) * Marco Squarcina (@lavish), [Security & Privacy Research Unit, TU Wien](https://secpriv.wien/)

CVE-2023-27495 Affected @fastify/csrf protection Versions

2 component(s)
Fixed Versions:
4.1.06.3.0
Product / Package Ecosystem Affected Versions Fixed Version
@fastify/csrf-protection
npm
< 4.1.0
4.1.0
@fastify/csrf-protection
npm
≥ 5.0.0
< 6.3.0
6.3.0

References

Frequently Asked Questions

What is CVE-2023-27495?
CVE-2023-27495 is a security vulnerability in @fastify/csrf protection involving Bypass of CSRF protection in the presence of predictable userInfo under CWE-352: Cross-Site Request Forgery (CSRF).
Which @fastify/csrf protection versions are affected?
Affected versions include releases prior to 4.1.0, 6.3.0 across affected packages: @fastify/csrf-protection.
What version fixes CVE-2023-27495?
Upgrading to 4.1.0, 6.3.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @fastify/csrf-protection affected?
Yes, @fastify/csrf-protection is affected in releases prior to 4.1.0, 6.3.0. Upgrade your dependency to 4.1.0, 6.3.0 or later.
What is the CVSS score of CVE-2023-27495?
CVE-2023-27495 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2023-27495?
CVE-2023-27495 is classified under CWE-352: Cross-Site Request Forgery (CSRF) (The web application does not, or cannot, sufficiently verify whether a request was intentionally provided by the user who sent the request, which could have originated from an unauthorized actor.).
How can I check npm dependencies for CVE-2023-27495?
Run the dependency tree command: 'npm ls @fastify/csrf-protection'. 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-qrgf-9gpc-vrxw",
  "modified" : "2023-05-02T12:31:41Z",
  "published" : "2023-04-20T21:18:51Z",
  "aliases" : [ "CVE-2023-27495" ],
  "summary" : "Bypass of CSRF protection in the presence of predictable userInfo",
  "details" : "## Description\nThe [CSRF](https://owasp.org/www-community/attacks/csrf) protection enforced by the `@fastify/csrf-protection` library in combination with `@fastify/cookie` can be bypassed from network and same-site attackers under certain conditions.\n\n`@fastify/csrf-protection` supports an optional `userInfo` parameter that binds the CSRF token to the user. This parameter has been introduced to prevent cookie-tossing attacks as a fix for [CVE-2021-29624](https://www.cvedetails.com/cve/CVE-2021-29624). Whenever `userInfo` parameter is missing, or its value can be predicted for the target user account, network and [same-site](https://canitakeyoursubdomain.name/) attackers can 1. fixate a `_csrf` cookie in the victim's browser, and 2. forge CSRF tokens that are valid for the victim's session. This allows attackers to bypass the CSRF protection mechanism.\n\nAs a fix, `@fastify/csrf-protection` starting from version 6.3.0 (and v4.1.0) includes a server-defined secret `hmacKey` that cryptographically binds the CSRF token to the value of the `_csrf` cookie and the `userInfo` parameter, making tokens non-spoofable by attackers. This protection is effective as long as the `userInfo` parameter is unique for each user.\n\n### Patches\n\nThis is patched in version 6.3.0 and v4.1.0.\n\n### Workarounds\n\nAs a workaround, developers can use a random, non-predictable `userInfo` parameter for each user.\n\n## Credits\n* Pedro Adão (@pedromigueladao), [Instituto Superior Técnico, University of Lisbon](https://tecnico.ulisboa.pt/)\n* Marco Squarcina (@lavish), [Security & Privacy Research Unit, TU Wien](https://secpriv.wien/)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/csrf-protection"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.1.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/csrf-protection"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0"
      }, {
        "fixed" : "6.3.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fastify/csrf-protection/security/advisories/GHSA-qrgf-9gpc-vrxw"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/csrf-protection/security/advisories/GHSA-rc4q-9m69-gqp8"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-27495"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/csrf-protection/commit/be3e5761f37aa05c7c1ac8ed44499c51ecec8058"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fastify/csrf-protection"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/csrf-protection/releases/tag/v4.1.0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/csrf-protection/releases/tag/v6.3.0"
  }, {
    "type" : "WEB",
    "url" : "https://www.cvedetails.com/cve/CVE-2021-29624"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-352" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-04-20T21:18:51Z",
    "nvd_published_at" : "2023-04-20T18:15:07Z"
  }
}