CVE-2021-21353: Remote Code Execution in pug

pug Updated 02 Oct 2025

Summary

03/03/2021
Yes i
Moderate
6.8

CVE-2021-21353: Remote code execution via the pretty option. Affects pug versions < 3.0.1. Fixed in 3.0.1. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

The pug package is a popular template engine for Node.js applications. It allows developers to write HTML templates using a concise and expressive syntax. The package is widely used in web development projects to generate dynamic HTML content. However, a vulnerability has been discovered in the pug package that could allow remote code execution on the server-side.

Vulnerability Detail

The vulnerability (CVE-2021-21353) arises from the pretty option of the pug compiler. If an attacker can control this option, they can inject malicious code into the pug template, leading to remote code execution on the Node.js backend. This can be achieved by spreading user-provided objects, such as query parameters, into the pug template inputs. The impact of this vulnerability is significant as it allows an attacker to execute arbitrary code on the server, potentially leading to unauthorized access, data breaches, or other malicious activities.

How To Fix

Latest published version: 3.0.4 as of 22 Oct 2026

npm install pug@3.0.4

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

3.0.1

This is the first release that contains the fix.

npm install pug@3.0.1

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If you are unable to immediately upgrade to the patched versions, you can implement a workaround by ensuring that untrusted input is not passed to pug as the pretty option. For example, you can compile templates in advance before applying user input to them. By doing so, you can mitigate the risk of remote code execution.

Conclusion

The CVE-2021-21353 vulnerability in the pug package allows remote code execution on the server-side. To mitigate this vulnerability, it is recommended to upgrade to the patched versions (pug@3.0.1 or pug-code-gen@3.0.2) or implement the provided workaround. Regularly monitoring for vulnerabilities in your software is crucial to ensure the security of your applications. For further support on vulnerability remediation, you can contact DevNack.com.

See every vulnerability recorded for pug →

Share this vulnerability

FAQ

The vulnerability allows an attacker to execute arbitrary code on the server-side, potentially leading to unauthorized access, data breaches, or other malicious activities.

You can fix this vulnerability by upgrading to pug version 3.0.1 or pug-code-gen version 3.0.2. These versions include the necessary fixes to prevent remote code execution.

Yes, if you are unable to immediately upgrade, you can mitigate the risk by ensuring that untrusted input is not passed to pug as the pretty option. Compile templates in advance before applying user input to them.

There is no known public exploit for this vulnerability at the moment. However, it is crucial to patch the vulnerability as soon as possible to prevent any potential attacks.

You can find more information about this vulnerability in the original report on GitHub: https://github.com/pugjs/pug/issues/3312

How To Fix

Latest published version: 3.0.4 as of 22 Oct 2026

npm install pug@3.0.4

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

3.0.1

This is the first release that contains the fix.

npm install pug@3.0.1

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback