CVE-2021-21353 Remote code execution in pug
Attackers can achieve remote code execution on Node.js backends by controlling the pretty option in the Pug template engine.
- Exploited in the wild
- Not known
- Login needed
- Not needed
- Attackable
- Over the internet
- Victim action needed
- Not needed
- Fix
- Available
What is CVE-2021-21353?
CVE-2021-21353 is a medium-severity code injection vulnerability in pugjs pug, published on 3 Mar 2021. An attacker can exploit it over the internet without logging in, with no action from the victim.
Official description
Pug is an npm package which is a high-performance template engine. In pug before version 3.0.1, 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. This is fixed in version 3.0.1. This advisory applies to multiple pug packages including "pug", "pug-code-gen". pug-code-gen has a backported fix at version 2.0.3. This advisory is not exploitable 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.
Which versions are affected by CVE-2021-21353?
6 open source packages ship an affected version, including pug-code-gen and pug. It affects 2 products.
| Package | Affected | Fixed in |
|---|---|---|
pug-code-gen npm | All versions | 2.0.3 |
pug-code-gen npm | All versions | 2.0.3 |
pug-code-gen npm | From 3.0.0 | 3.0.2 |
pug-code-gen npm | From 3.0.0 | 3.0.2 |
pug npm | All versions | 3.0.1 |
pug npm | All versions | 3.0.1 |
Products include Pugjs Pug, Pugjs Pug-Code-Gen.
How do I fix CVE-2021-21353?
Upgrade pug-code-gen to a fixed version for your release line: 2.0.3 or 3.0.2.
Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.
Is CVE-2021-21353 being exploited?
There is no known exploitation of CVE-2021-21353 in the wild and no public exploit code.
Public exploit code: 1 proofs of concept on GitHub.
Sources
Also known as GHSA-p493-635q-r6gr, MINI-627x-gw6c-4p2q, MINI-j32f-4p8p-hm5x, ROOT-APP-NPM-CVE-2021-21353.