CVE-2021-21353: Pug Remote Code Execution Vulnerability

MODERATE
Advisory Identifier: GHSA-p493-635q-r6gr
CVSS 6.8
CWE-94 CWE-74
Published
Advisory Summary

CVE-2021-21353 is a MODERATE (CVSS 6.8) remote code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Pug libraries in the npm ecosystem. The issue involves remote code execution via the `pretty` option.. Remediation is available by upgrading affected packages to version 3.0.1, 2.0.3, 3.0.2.

CVE-2021-21353 at a Glance

CVE Identifier CVE-2021-21353
GHSA Identifier GHSA-p493-635q-r6gr
Severity MODERATE
CVSS v3.1 Base Score 6.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Pug
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.8

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

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

How to Fix CVE-2021-21353

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

pug fixed: 3.0.1
npm install pug@3.0.1
pug-code-gen fixed: 2.0.3
npm install pug-code-gen@2.0.3
pug-code-gen fixed: 3.0.2
npm install pug-code-gen@3.0.2
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 pug

How to Check if You Are Affected

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

npm ls pug

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

Note: The npm ls pug 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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Pug, 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 If a remote attacker was able to control the `pretty` option of the pug compiler, e.g. if you spread a user provided object such as the query parameters of a request into the pug template inputs, it was possible for them to achieve remote code execution on the node.js backend. ### Patches Upgrade to `pug@3.0.1` or `pug-code-gen@3.0.2` or `pug-code-gen@2.0.3`, which correctly sanitise the parameter. ### Workarounds If there is no way for un-trusted input to be passed to pug as the `pretty` option, e.g. if you compile templates in advance before applying user input to them, you do not need to upgrade. ### References Original report: https://github.com/pugjs/pug/issues/3312 ### For more information If you believe you have found other vulnerabilities, please **DO NOT** open an issue. Instead, you can follow the instructions in our [Security Policy](https://github.com/pugjs/pug/blob/master/SECURITY.md)

CVE-2021-21353 Affected Pug Versions

3 component(s)
Fixed Versions:
3.0.12.0.33.0.2
Product / Package Ecosystem Affected Versions Fixed Version
pug
npm
< 3.0.1
3.0.1
pug-code-gen
npm
< 2.0.3
2.0.3
pug-code-gen
npm
≥ 3.0.0
< 3.0.2
3.0.2

References

Frequently Asked Questions

What is CVE-2021-21353?
CVE-2021-21353 is a security vulnerability in Pug involving Remote code execution via the `pretty` option. under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Pug versions are affected?
Affected versions include releases prior to 3.0.1, 2.0.3, 3.0.2 across affected packages: pug, pug-code-gen.
What version fixes CVE-2021-21353?
Upgrading to 3.0.1, 2.0.3, 3.0.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is pug affected?
Yes, pug is affected in releases prior to 3.0.1. Upgrade your dependency to 3.0.1 or later.
Is pug-code-gen affected?
Yes, pug-code-gen is affected in releases prior to 2.0.3, 3.0.2. Upgrade your dependency to 2.0.3, 3.0.2 or later.
What is the CVSS score of CVE-2021-21353?
CVE-2021-21353 has a CVSS v3.1 base score of 6.8 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:N/I:H/A:N.
What CWE is associated with CVE-2021-21353?
CVE-2021-21353 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2021-21353?
Run the dependency tree command: 'npm ls pug'. 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-p493-635q-r6gr",
  "modified" : "2025-04-16T22:09:45Z",
  "published" : "2021-03-03T02:03:52Z",
  "aliases" : [ "CVE-2021-21353" ],
  "summary" : "Remote code execution via the `pretty` option.",
  "details" : "### Impact\n\nIf a remote attacker was able to control the `pretty` option of the pug compiler, e.g. if you spread a user provided object such as the query parameters of a request into the pug template inputs, it was possible for them to achieve remote code execution on the node.js backend.\n\n### Patches\n\nUpgrade to `pug@3.0.1` or `pug-code-gen@3.0.2` or `pug-code-gen@2.0.3`, which correctly sanitise the parameter.\n\n### Workarounds\n\nIf there is no way for un-trusted input to be passed to pug as the `pretty` option, e.g. if you compile templates in advance before applying user input to them, you do not need to upgrade.\n\n### References\n\n\nOriginal report: https://github.com/pugjs/pug/issues/3312\n\n### For more information\n\nIf you believe you have found other vulnerabilities, please **DO NOT** open an issue. Instead, you can follow the instructions in our [Security Policy](https://github.com/pugjs/pug/blob/master/SECURITY.md)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "pug"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.0.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "pug-code-gen"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.0.3"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "pug-code-gen"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "3.0.0"
      }, {
        "fixed" : "3.0.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pugjs/pug/security/advisories/GHSA-p493-635q-r6gr"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-21353"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pugjs/pug/issues/3312"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pugjs/pug/pull/3314"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pugjs/pug/commit/991e78f7c4220b2f8da042877c6f0ef5a4683be0"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pugjs/pug/releases/tag/pug%403.0.1"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/pug"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/pug-code-gen"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-74", "CWE-94" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-03-03T01:49:22Z",
    "nvd_published_at" : "2021-03-03T02:15:00Z"
  }
}