CVE-2021-21353: Pug Remote Code Execution Vulnerability
MODERATECVE-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
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).
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.
npm install pug@3.0.1
npm install pug-code-gen@2.0.3
npm install pug-code-gen@3.0.2
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
CVE-2021-21353 Affected Pug Versions
3 component(s)| 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?
Which Pug versions are affected?
What version fixes CVE-2021-21353?
Is pug affected?
Is pug-code-gen affected?
What is the CVSS score of CVE-2021-21353?
What CWE is associated with CVE-2021-21353?
How can I check npm dependencies for CVE-2021-21353?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"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"
}
}