Critical Vulnerability in Jinja2: Arbitrary Code Execution via |attr Filter
Summary
CVE-2025-27516: Jinja is an extensible templating engine. Affects py3-jinja2 across 2 version ranges.
< 3.1.6-r0
< 90457bbf33b8662926ae65cdde4c4c32e756e403
Fixed in 3.1.6-r0. How to fix ↓
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.
No signup required · Results in about 60 seconds
Background
Jinja2 is an extensible templating engine for Python, widely used for rendering templates in web applications. It allows developers to create dynamic web pages by embedding Python-like expressions within HTML. Jinja2's sandboxing feature is designed to execute untrusted templates safely, but it has a vulnerability that can be exploited if an attacker controls the template content.
Vulnerability Detail
The vulnerability, identified as CVE-2025-27516, arises from an oversight in the Jinja sandboxed environment's interaction with the |attr filter. This flaw allows an attacker who controls template content to execute arbitrary Python code, potentially compromising the application. The vulnerability affects applications that execute untrusted templates, as the |attr filter can bypass the sandbox's restrictions, leading to unauthorized access and execution of code.
How To Fix
Minimum fixed version
3.1.6-r0
This is the first release that contains the fix.
sudo apk add --upgrade py3-jinja2
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a temporary workaround, avoid using the |attr filter in templates that may be controlled by untrusted users. Instead, consider using safer alternatives or sanitizing input to prevent exploitation.
Conclusion
CVE-2025-27516 is a critical vulnerability in Jinja2 that allows for arbitrary code execution through the |attr filter. It is essential for developers to update to version 3.1.6 or later to protect their applications. Utilizing tools like Vulert can help monitor and identify vulnerabilities in real-time.
See every vulnerability recorded for py3-jinja2 →
FAQ
CVE-2025-27516 is a vulnerability in Jinja2 that allows arbitrary code execution through the |attr filter if an attacker controls the template content.
You can check if your application is affected by using Vulert, which monitors open-source vulnerabilities in your software. Visit Vulert Scanner to analyze your manifest file.
The risks include unauthorized execution of arbitrary Python code, which can lead to data breaches, system compromise, and loss of integrity in your application.
Yes, the vulnerability is fixed in Jinja2 version 3.1.6 and later. It is recommended to update your package to this version.
If immediate updates are not possible, avoid using the |attr filter in your templates and consider implementing input validation to mitigate the risk.
Related vulnerabilities
Recent vulnerabilities recorded for py3-jinja2.