CVE-2014-1402: Incorrect Privilege Assignment in Jinja2
Summary
CVE-2014-1402: Incorrect Privilege Assignment in Jinja2. Affects jinja2 versions < 2.7.2. Fixed in 2.7.2. How to fix ↓
Also tracked for
- jinja2 · Debian:11
The same CVE-2014-1402 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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 a popular templating engine for Python. It provides a way to generate dynamic content by combining templates with data. Jinja2 is widely used in web development frameworks and other applications that require dynamic content generation. However, a vulnerability has been discovered in Jinja2 versions prior to 2.7.2 that allows local users to gain privileges through a specific file manipulation technique.
Vulnerability Detail
The vulnerability in Jinja2 arises from the default configuration of bccache.FileSystemBytecodeCache. This component is responsible for caching compiled templates to improve performance. However, it fails to properly create temporary files, which can be exploited by local users. An attacker can craft a malicious .cache file with a name starting with '_jinja2' in the /tmp directory. When Jinja2 attempts to load this file, it inadvertently grants the attacker elevated privileges. This privilege escalation can lead to unauthorized access, data manipulation, or other malicious activities.
How To Fix
Latest published version: 3.1.6 as of 23 Oct 2026
pip install --upgrade "jinja2==3.1.6"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
2.7.2
This is the first release that contains the fix.
pip install --upgrade "jinja2==2.7.2"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If upgrading to the latest version of Jinja2 is not immediately feasible, a temporary workaround can be implemented. The workaround involves modifying the default configuration of bccache.FileSystemBytecodeCache to use a different directory for temporary files. By specifying a secure directory with restricted access, the risk of privilege escalation can be mitigated. Here is an example of how to modify the configuration:
import jinja2
jinja2.defaults.DEFAULT_CACHE_SIZE = 0
jinja2.Environment(bytecode_cache=jinja2.FileSystemBytecodeCache('/secure/temp/dir'))
This code snippet sets the cache size to 0 to disable caching and specifies a secure directory ('/secure/temp/dir') for temporary files.
Conclusion
In conclusion, the vulnerability in Jinja2 (CVE-2014-1402) allows local users to gain elevated privileges through a specific file manipulation technique. To mitigate this vulnerability, it is recommended to upgrade to Jinja2 version 2.7.2 or later. If immediate upgrade is not feasible, a temporary workaround can be implemented by modifying the configuration. For further assistance and support in vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for jinja2 →
FAQ
Jinja2 is a templating engine for Python that allows dynamic content generation by combining templates with data. It is widely used in web development frameworks and other applications.
The vulnerability allows local users to gain elevated privileges, which can lead to unauthorized access, data manipulation, or other malicious activities.
Versions of Jinja2 prior to 2.7.2 are affected by this vulnerability.
To fix this vulnerability, it is recommended to upgrade Jinja2 to version 2.7.2 or later. Alternatively, you can implement the provided workaround to mitigate the risk.
Yes, a workaround is available. By modifying the configuration of bccache.FileSystemBytecodeCache to use a secure directory for temporary files, the risk of privilege escalation can be reduced.
Related vulnerabilities
Recent vulnerabilities recorded for jinja2.