External risk intelligence

Pug Template Engine Remote Code Execution Vulnerability.

CVE advisorySeverity: CRITICAL (CVSS 9.0)

CVE-2021-21353

Pug is a widely used template engine for Node.js web applications. Because the vulnerability involves passing user-supplied input to the template compiler, it is commonly deployed in web-facing applications where query parameters or request data are processed. While it depends on specific coding patterns, it is frequently found in internet-facing web application stacks.

Halo Surface Signal: 4 out of 5 — likely to be public-facing.

External exposure likelihood

Horizon Alert

Summary of the vulnerability and why it matters

A vulnerability has been identified in the Pug template engine, a component used in some Node.js applications. If an attacker can influence a specific setting within the compiler, it may allow them to execute arbitrary code on the backend. This risk is mitigated if untrusted input is not directly passed to the compiler's `pretty` option, such as when templates are pre-compiled.

  • Allows attackers to run code on backend servers.
  • Matters if user input directly controls compiler settings.
  • Confirm if user input affects template compilation.

Attack Path

How an attacker could exploit the issue

An attacker could exploit this vulnerability if they can control the `pretty` option passed to the Pug template compiler. This typically occurs when user-supplied input, such as query parameters from a web request, is directly used in compiling Pug templates on a Node.js backend. Successful exploitation could allow an attacker to execute arbitrary code on the server.

  • No special access required.
  • User input controls `pretty` option.
  • Remote code execution risk.

Live Threat

Current exploitation, exposure, and threat context

When a remote attacker can control the `pretty` option passed to the Pug compiler, such as by manipulating query parameters of a request, it could lead to remote code execution on the Node.js backend. This threat is mitigated if templates are compiled in advance, before user input is processed.

  • Node.js backend code execution.
  • Remote attacker controls `pretty` option.
  • Compromised backend services.

Operational Fix

Recommended remediation, mitigation, and detection steps

System owners and platform teams responsible for Node.js backends should first confirm where Pug is deployed and if untrusted input can reach the `pretty` option. This will determine the actual risk and the need for remediation, which may involve coordination with application development teams or vendor management if the issue lies with a third-party integration. The practical first step is to inventory all Pug instances, assess their exposure and criticality, and identify the accountable owners before planning any updates or mitigation strategies.

  • Application and platform teams own remediation.
  • Verify untrusted input reaches the `pretty` option.
  • Plan remediation based on exposure and criticality.

Supplementary metadata

Validate whether this threat affects your internet-facing exposure.

Halo Threat Intelligence helps prioritize remediation with Halo Surface Signal and H/A/L/O context. Start exposure validation with a free external attack surface trial.

Frequently asked questions

What is the Pug package and how is it used?

Pug is a popular, high-performance template engine built for Node.js. Developers use it to transform concise, readable code into standard HTML, often to dynamically render pages or emails on the server side before sending them to a user's browser.

How does CVE-2021-21353 create a security weakness?

This vulnerability involves improper control of generation of code, classified as CWE-94 and CWE-74. If an attacker influences the 'pretty' configuration option used during compilation, they can inject malicious instructions that the Node.js backend executes.

Do I need to worry if I pre-compile my templates?

No. The vulnerability requires untrusted user input to reach the 'pretty' option during the actual compilation process. If you compile your templates in advance before applying user data, the specific trigger path for this code execution flaw does not exist.

Why does Halo Surface Signal categorize this as external?

Halo Surface Signal identifies this as a potential external risk because Pug is commonly deployed within internet-facing web application stacks. If your web app processes query parameters or user-provided objects, it may inadvertently pass that data to the template compiler, creating an internet-accessible attack surface.

How do I respond to the CVE-2021-21353 advisory?

Start by identifying where your application uses Pug to render templates. Audit your code to ensure no user-controlled data can influence the 'pretty' compiler option. If you find such patterns, update to Pug version 3.0.1 or higher, or pug-code-gen version 2.0.3 or higher, to apply the necessary security fixes.

References