Vulnerabilities in pkg:npm/@fastify/passport

PACKAGE
Advisory Identifier: GHSA-2ccf-ffrj-m4qw
Advisory Summary

CVE-2023-29020 is a MODERATE (CVSS 6.5) csrf token fixation vulnerability (CWE-352: Cross-Site Request Forgery (CSRF)) affecting @fastify/passport libraries in the npm ecosystem. The issue involves csrf token fixation in fastify-passport. Remediation is available by upgrading affected packages to version 1.1.0, 2.3.0.

2 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/@fastify/passport

2 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/@fastify/passport. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-2ccf-ffrj-m4qw CVE-2023-29020 MODERATE CSRF token fixation in fastify-passport
GHSA-4m3m-ppvx-xgw9 CVE-2023-29019 HIGH Session fixation in fastify-passport

CVE-2023-29020 at a Glance

CVE Identifier CVE-2023-29020
GHSA Identifier GHSA-2ccf-ffrj-m4qw
Severity MODERATE
CVSS v3.1 Base Score 6.5
CWE Classification CWE-352: Cross-Site Request Forgery (CSRF)
Affected Product @fastify/passport
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.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:R/S:U/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
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-29020

To remediate this vulnerability, upgrade all affected @fastify/passport 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/passport fixed: 1.1.0
npm install @fastify/passport@1.1.0
@fastify/passport fixed: 2.3.0
npm install @fastify/passport@2.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/passport

How to Check if You Are Affected

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

npm ls @fastify/passport

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

Note: The npm ls @fastify/passport 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/passport, 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

The [CSRF](https://owasp.org/www-community/attacks/csrf) protection enforced by the `@fastify/csrf-protection` library, when combined with `@fastify/passport`, can be bypassed by network and same-site attackers. ## Details `fastify/csrf-protection` implements the [synchronizer token pattern](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#synchronizer-token-pattern) (using plugins `@fastify/session` and `@fastify/secure-session`) by storing a random value used for CSRF token generation in the `_csrf` attribute of a user's session. The `@fastify/passport` library does not clear the session object upon authentication, preserving the `_csrf` attribute between pre-login and authenticated sessions. Consequently, CSRF tokens generated before authentication are still valid. Network and [same-site attackers](https://canitakeyoursubdomain.name/) can thus obtain a CSRF token for their pre-session, fixate that pre-session in the victim's browser via cookie tossing, and then perform a CSRF attack after the victim authenticates. ## Fix As a solution, newer versions of `@fastify/passport` include the configuration options * `clearSessionOnLogin (default: true)` and * `clearSessionIgnoreFields (default: ['session'])` to clear all the session attributes by default, preserving those explicitly defined in `clearSessionIgnoreFields`. ## 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-29020 Affected @fastify/passport Versions

2 component(s)
Fixed Versions:
1.1.02.3.0
Product / Package Ecosystem Affected Versions Fixed Version
@fastify/passport
npm
< 1.1.0
1.1.0
@fastify/passport
npm
≥ 2.0.0
< 2.3.0
2.3.0

References

Frequently Asked Questions

What is CVE-2023-29020?
CVE-2023-29020 is a security vulnerability in @fastify/passport involving CSRF token fixation in fastify-passport under CWE-352: Cross-Site Request Forgery (CSRF).
Which @fastify/passport versions are affected?
Affected versions include releases prior to 1.1.0, 2.3.0 across affected packages: @fastify/passport.
What version fixes CVE-2023-29020?
Upgrading to 1.1.0, 2.3.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @fastify/passport affected?
Yes, @fastify/passport is affected in releases prior to 1.1.0, 2.3.0. Upgrade your dependency to 1.1.0, 2.3.0 or later.
What is the CVSS score of CVE-2023-29020?
CVE-2023-29020 has a CVSS v3.1 base score of 6.5 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2023-29020?
CVE-2023-29020 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-29020?
Run the dependency tree command: 'npm ls @fastify/passport'. 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-2ccf-ffrj-m4qw",
  "modified" : "2023-04-24T15:56:27Z",
  "published" : "2023-04-21T22:32:47Z",
  "aliases" : [ "CVE-2023-29020" ],
  "summary" : "CSRF token fixation in fastify-passport",
  "details" : "The [CSRF](https://owasp.org/www-community/attacks/csrf) protection enforced by the `@fastify/csrf-protection` library, when combined with `@fastify/passport`, can be bypassed by network and same-site attackers.\n\n## Details\n`fastify/csrf-protection` implements the [synchronizer token pattern](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#synchronizer-token-pattern) (using plugins `@fastify/session` and `@fastify/secure-session`) by storing a random value used for CSRF token generation in the `_csrf` attribute of a user's session.\n\nThe `@fastify/passport` library does not clear the session object upon authentication, preserving the `_csrf` attribute between pre-login and authenticated sessions. Consequently, CSRF tokens generated before authentication are still valid. Network and [same-site attackers](https://canitakeyoursubdomain.name/) can thus obtain a CSRF token for their pre-session, fixate that pre-session in the victim's browser via cookie tossing, and then perform a CSRF attack after the victim authenticates.\n\n## Fix\nAs a solution, newer versions of `@fastify/passport` include the configuration options\n\n* `clearSessionOnLogin (default: true)` and\n* `clearSessionIgnoreFields (default: ['session'])`\n\nto clear all the session attributes by default, preserving those explicitly defined in `clearSessionIgnoreFields`.\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:L/PR:N/UI:R/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/passport"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.1.0"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/passport"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "2.0.0"
      }, {
        "fixed" : "2.3.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-passport/security/advisories/GHSA-2ccf-ffrj-m4qw"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-29020"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-passport/commit/07c90feab9cba0dd4779e47cfb0717a7e2f01d3d"
  }, {
    "type" : "WEB",
    "url" : "https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html#synchronizer-token-pattern"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fastify/fastify-passport"
  }, {
    "type" : "WEB",
    "url" : "https://owasp.org/www-community/attacks/csrf"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-352" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-04-21T22:32:47Z",
    "nvd_published_at" : "2023-04-21T23:15:20Z"
  }
}