Server-Side Template Injection in node-ejs

node-ejs Updated 02 Oct 2025

Summary

04/05/2023
N/A
No i
Critical
9.8

CVE-2023-29827: ejs v3.1.9 is vulnerable to server-side template injection. Affects node-ejs versions < aed012481d11ee9e8ca024314262b90de7c6d91e. No fix is published. 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 Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

node-ejs is a popular package used for server-side rendering of templates in Node.js applications. It provides a simple and efficient way to generate dynamic HTML content. However, a vulnerability has been discovered in version 3.1.9 of the package, which allows for server-side template injection.

Vulnerability Detail

The vulnerability (CVE-2023-29827) in node-ejs version 3.1.9 arises from the improper handling of the closeDelimiter configuration setting. If an attacker can control the ejs file, they can exploit this vulnerability to inject malicious code into the server-side template. This can lead to various security risks, including remote code execution, data leakage, and privilege escalation. It is important to note that the vendor disputes this vulnerability, claiming that the render function is not intended to be used with untrusted input.

How To Fix

No fixed version is published for this vulnerability.

Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →

Workaround

If upgrading to a patched version is not immediately feasible, a temporary workaround can be implemented by disabling the use of untrusted input in the render function. This can be achieved by validating and sanitizing any user-supplied data before passing it to the render function. Here is an example of how to sanitize user input using the 'sanitize-html' package:

const sanitizeHtml = require('sanitize-html');

const userInput = req.body.userInput;
const sanitizedInput = sanitizeHtml(userInput);

ejs.render(template, { userInput: sanitizedInput });

Conclusion

In conclusion, node-ejs version 3.1.9 is vulnerable to server-side template injection. It is crucial to upgrade to a patched version or implement the suggested workaround to mitigate the risk of exploitation. For further assistance and support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for node-ejs →

Share this vulnerability

FAQ

node-ejs is a package for server-side rendering of templates in Node.js applications. It allows developers to generate dynamic HTML content by combining templates with data.

Server-side template injection is a vulnerability that occurs when untrusted user input is directly embedded in a server-side template. This can lead to the execution of arbitrary code on the server and potential security breaches.

An attacker can exploit this vulnerability by controlling the ejs file and injecting malicious code through the closeDelimiter configuration setting. This can lead to various security risks, including remote code execution and data leakage.

The vendor disputes this vulnerability, claiming that the render function is not intended to be used with untrusted input. However, it is still important to take precautions and follow best practices to mitigate the potential risks.

There have been no known instances of this vulnerability being exploited in the wild. However, it is always recommended to stay updated with the latest security patches and follow secure coding practices to minimize the risk of exploitation.

Related vulnerabilities

Recent vulnerabilities recorded for node-ejs.

How To Fix

No fixed version is published for this vulnerability.

Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. 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