CVE-2023-2142: Nunjucks Nunjucks Autoescape Bypass Leads To Vulnerability

MODERATE
Advisory Identifier: GHSA-x77j-w7wf-fjmw
CVSS 6.1
CWE-79
Published
Advisory Summary

CVE-2023-2142 is a MODERATE (CVSS 6.1) nunjucks autoescape bypass leads to vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Nunjucks libraries in the npm ecosystem. The issue involves nunjucks autoescape bypass leads to cross site scripting. Remediation is available by upgrading affected packages to version 3.2.4.

CVE-2023-2142 at a Glance

CVE Identifier CVE-2023-2142
GHSA Identifier GHSA-x77j-w7wf-fjmw
Severity MODERATE
CVSS v3.1 Base Score 6.1
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Nunjucks
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.1

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:L/I:L/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 Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2023-2142

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

nunjucks fixed: 3.2.4
npm install nunjucks@3.2.4
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 nunjucks

How to Check if You Are Affected

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

npm ls nunjucks

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

Note: The npm ls nunjucks 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-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Nunjucks, 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 In Nunjucks versions prior to version 3.2.4, it was possible to bypass the restrictions which are provided by the autoescape functionality. If there are two user-controlled parameters on the same line used in the views, it was possible to inject cross site scripting payloads using the backslash `\` character. #### Example If the user-controlled parameters were used in the views similar to the following: ``` <script> let testObject = { lang: '{{ lang }}', place: '{{ place }}' }; </script> ``` It is possible to inject XSS payload using the below parameters: ``` https://<application-url>/?lang=jp\&place=};alert(document.domain)// ``` ### Patches The issue was patched in version 3.2.4. ### References - https://bugzilla.mozilla.org/show_bug.cgi?id=1825980

CVE-2023-2142 Affected Nunjucks Versions

1 component(s)
Fixed Versions:
3.2.4
Product / Package Ecosystem Affected Versions Fixed Version
nunjucks
npm
< 3.2.4
3.2.4

References

Frequently Asked Questions

What is CVE-2023-2142?
CVE-2023-2142 is a security vulnerability in Nunjucks involving Nunjucks autoescape bypass leads to cross site scripting under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Nunjucks versions are affected?
Affected versions include releases prior to 3.2.4 across affected packages: nunjucks.
What version fixes CVE-2023-2142?
Upgrading to 3.2.4 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nunjucks affected?
Yes, nunjucks is affected in releases prior to 3.2.4. Upgrade your dependency to 3.2.4 or later.
What is the CVSS score of CVE-2023-2142?
CVE-2023-2142 has a CVSS v3.1 base score of 6.1 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2023-2142?
CVE-2023-2142 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check npm dependencies for CVE-2023-2142?
Run the dependency tree command: 'npm ls nunjucks'. 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-x77j-w7wf-fjmw",
  "modified" : "2024-11-26T18:54:25Z",
  "published" : "2023-04-20T21:19:24Z",
  "aliases" : [ "CVE-2023-2142" ],
  "summary" : "Nunjucks autoescape bypass leads to cross site scripting",
  "details" : "### Impact\nIn Nunjucks versions prior to version 3.2.4, it was possible to bypass the restrictions which are provided by the autoescape functionality. If there are two user-controlled parameters on the same line used in the views, it was possible to inject cross site scripting payloads using the backslash `\\` character.\n\n#### Example\nIf the user-controlled parameters were used in the views similar to the following:\n```\n<script>\nlet testObject = { lang: '{{ lang }}', place: '{{ place }}' };\n</script>\n```\n\nIt is possible to inject XSS payload using the below parameters:\n```\nhttps://<application-url>/?lang=jp\\&place=};alert(document.domain)//\n```\n\n### Patches\nThe issue was patched in version 3.2.4.\n\n### References\n\n- https://bugzilla.mozilla.org/show_bug.cgi?id=1825980\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "nunjucks"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.2.4"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mozilla/nunjucks/security/advisories/GHSA-x77j-w7wf-fjmw"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-2142"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mozilla/nunjucks/pull/1437"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mozilla/nunjucks/commit/ec16d210e7e13f862eccdb0bc9af9f60ff6749d6"
  }, {
    "type" : "WEB",
    "url" : "https://bugzilla.mozilla.org/show_bug.cgi?id=1825980"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mozilla/nunjucks"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mozilla/nunjucks/releases/tag/v3.2.4"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-04-20T21:19:24Z",
    "nvd_published_at" : "2024-11-26T12:15:18Z"
  }
}