Jinja Sandbox Bypass Vulnerability Allowing Arbitrary Code Execution

Vulnerability

A vulnerability in Jinja prior to version 3.1.6 allows for arbitrary code execution by bypassing the sandboxed environment. This issue arises from an oversight in how the sandbox interacts with the |attr filter, enabling an attacker to exploit untrusted templates. While Jinja's sandbox typically prevents calls to str.format from escaping, the |attr filter can be manipulated to access a string's format method, circumventing the sandbox's protections. Applications that execute untrusted templates are particularly vulnerable.

Impact

Exploitation of this vulnerability could lead to arbitrary code execution on the server where the vulnerable Jinja template is processed.

Reproduction

To reproduce this vulnerability, create a Jinja template that includes the |attr filter applied to a string. The template must be processed in an application that uses Jinja and allows for the execution of untrusted templates. When the template is rendered, the |attr filter can be used to access the string's format method, bypassing the sandbox and executing arbitrary Python code.

Remediation

Users should upgrade to Jinja version 3.1.6 or later, where this vulnerability has been fixed.

Added: Jun 9, 2025, 7:46 PM
Updated: Jun 9, 2025, 7:46 PM

Vulnerability Rating

Custom Algorithm
spread
7.8
impact
7.5
exploitability
5.3
remediation
7.7
relevance
0.0
threat
4.8
urgency
2.9
incentive
1.7

Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.