CVE-2023-31999: @fastify/oauth2 @fastify/oauth2 Vulnerable To Cross Site Vulnerability

HIGH
Advisory Identifier: GHSA-g8x5-p9qc-cf95
CVSS 7.4
CWE-352
Published
Advisory Summary

CVE-2023-31999 is a HIGH (CVSS 7.4) @fastify/oauth2 vulnerable to cross site vulnerability (CWE-352: Cross-Site Request Forgery (CSRF)) affecting @fastify/oauth2 libraries in the npm ecosystem. The issue involves @fastify/oauth2 vulnerable to cross site request forgery due to reused oauth2 state. Remediation is available by upgrading affected packages to version 7.2.0.

CVE-2023-31999 at a Glance

CVE Identifier CVE-2023-31999
GHSA Identifier GHSA-g8x5-p9qc-cf95
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-352: Cross-Site Request Forgery (CSRF)
Affected Product @fastify/oauth2
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.4

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:C/C:H/I:N/A:N).

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

How to Fix CVE-2023-31999

To remediate this vulnerability, upgrade all affected @fastify/oauth2 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/oauth2 fixed: 7.2.0
npm install @fastify/oauth2@7.2.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/oauth2

How to Check if You Are Affected

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

npm ls @fastify/oauth2

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

Note: The npm ls @fastify/oauth2 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/oauth2, 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 All versions of @fastify/oauth2 used a statically generated `state` parameter at startup time and were used across all requests for all users. The purpose of the Oauth2 `state` parameter is to prevent Cross-Site-Request-Forgery attacks. As such, it should be unique per user and should be connected to the user's session in some way that will allow the server to validate it. ### Patches v7.2.0 changes the default behavior to store the `state` in a cookie with the `http-only` and `same-site=lax` attributes set. The state is now by default generated for every user. Note that this contains a breaking change in the `checkStateFunction` function, which now accepts the full `Request` object. ### Workarounds There are no known workarounds. ### References * [Prevent Attacks and Redirect Users with OAuth 2.0 State Parameters](https://auth0.com/docs/secure/attack-protection/state-parameters)

CVE-2023-31999 Affected @fastify/oauth2 Versions

1 component(s)
Fixed Versions:
7.2.0
Product / Package Ecosystem Affected Versions Fixed Version
@fastify/oauth2
npm
< 7.2.0
7.2.0

References

Frequently Asked Questions

What is CVE-2023-31999?
CVE-2023-31999 is a security vulnerability in @fastify/oauth2 involving @fastify/oauth2 vulnerable to Cross Site Request Forgery due to reused Oauth2 state under CWE-352: Cross-Site Request Forgery (CSRF).
Which @fastify/oauth2 versions are affected?
Affected versions include releases prior to 7.2.0 across affected packages: @fastify/oauth2.
What version fixes CVE-2023-31999?
Upgrading to 7.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @fastify/oauth2 affected?
Yes, @fastify/oauth2 is affected in releases prior to 7.2.0. Upgrade your dependency to 7.2.0 or later.
What is the CVSS score of CVE-2023-31999?
CVE-2023-31999 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N.
What CWE is associated with CVE-2023-31999?
CVE-2023-31999 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-31999?
Run the dependency tree command: 'npm ls @fastify/oauth2'. 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-g8x5-p9qc-cf95",
  "modified" : "2023-07-06T20:39:29Z",
  "published" : "2023-07-05T21:36:56Z",
  "aliases" : [ "CVE-2023-31999" ],
  "summary" : "@fastify/oauth2 vulnerable to Cross Site Request Forgery due to reused Oauth2 state",
  "details" : "### Impact\n\nAll versions of @fastify/oauth2 used a statically generated `state` parameter at startup time and were used across all requests for all users.\nThe purpose of the Oauth2 `state` parameter is to prevent Cross-Site-Request-Forgery attacks. As such, it should be unique per user and should be connected to the user's session in some way that will allow the server to validate it.\n\n### Patches\n\nv7.2.0 changes the default behavior to store the `state` in a cookie with the `http-only` and `same-site=lax` attributes set. The state is now by default generated for every user.\n\nNote that this contains a breaking change in the `checkStateFunction` function, which now accepts the full `Request` object.\n\n### Workarounds\n\nThere are no known workarounds.\n\n### References\n\n* [Prevent Attacks and Redirect Users with OAuth 2.0 State Parameters](https://auth0.com/docs/secure/attack-protection/state-parameters)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/oauth2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "7.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-oauth2/security/advisories/GHSA-g8x5-p9qc-cf95"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-35935"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-oauth2/commit/bff756b456cbb769080631af2beb85671ff4c79c"
  }, {
    "type" : "WEB",
    "url" : "https://auth0.com/docs/secure/attack-protection/state-parameters"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fastify/fastify-oauth2"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-oauth2/releases/tag/v7.2.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-352" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-07-05T21:36:56Z",
    "nvd_published_at" : "2023-07-03T17:15:09Z"
  }
}