CVE-2025-27516: Jinja2 vulnerable to sandbox breakout through attr filter selecting format method

Published Mar 5, 2025
·
Updated

An oversight in how the Jinja sandboxed environment interacts with the |attr filter allows an attacker that controls the content of a template to execute arbitrary Python code.

To exploit the vulnerability, an attacker needs to control the content of a template. Whether that is the case depends on the type of application using Jinja. This vulnerability impacts users of applications which execute untrusted templates.

Jinja's sandbox does catch calls to str.format and ensures they don't escape the sandbox. However, it's possible to use the |attr filter to get a reference to a string's plain format method, bypassing the sandbox. After the fix, the |attr filter no longer bypasses the environment's attribute lookup.

Other sources

Jinja is an extensible templating engine. Prior to 3.1.6, an oversight in how the Jinja sandboxed environment interacts with the |attr filter allows an attacker that controls the content of a template to execute arbitrary Python code. To exploit the vulnerability, an attacker needs to control the content of a template. Whether that is the case depends on the type of application using Jinja. This vulnerability impacts users of applications which execute untrusted templates. Jinja's sandbox does catch calls to str.format and ensures they don't escape the sandbox. However, it's possible to use the |attr filter to get a reference to a string's plain format method, bypassing the sandbox. After the fix, the |attr filter no longer bypasses the environment's attribute lookup. This vulnerability is fixed in 3.1.6.

— NVD

Affected Software

23 affected componentsFixes available
pip/jinja2<=3.1.5
3.1.6
palletsprojects Jinja<3.1.6
Debian Debian Linux=11.0
IBM SevOne Network Performance Management<=7.0.0 - 8.2.2
pip/jinja2<3.1.6
3.1.6
ubuntu/jinja2<2.7.2-2ubuntu0.1~esm6
2.7.2-2ubuntu0.1~esm6
ubuntu/jinja2<2.8-1ubuntu0.1+esm5
2.8-1ubuntu0.1+esm5
ubuntu/jinja2<2.10-1ubuntu0.18.04.1+esm4
2.10-1ubuntu0.18.04.1+esm4
ubuntu/jinja2<2.10.1-2ubuntu0.5
2.10.1-2ubuntu0.5
ubuntu/jinja2<3.0.3-1ubuntu0.4
3.0.3-1ubuntu0.4
ubuntu/jinja2<3.1.2-1ubuntu1.3
3.1.2-1ubuntu1.3
debian/jinja2
2.11.3-1+deb11u33.1.2-1+deb12u33.1.6-1
debian/jinja2<3.1.2-1+deb12u3
3.1.2-1+deb12u3
debian/jinja2<3.1.6-1
3.1.6-1
debian/jinja2<3.1.6-1
3.1.6-1
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0
alpine/py3-jinja2<3.1.6-r0
3.1.6-r0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/Jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.6
  2. Upgrade

    Upgrade pip/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.6
  3. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.7.2-2ubuntu0.1~esm6
  4. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.8-1ubuntu0.1+esm5
  5. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.10-1ubuntu0.18.04.1+esm4
  6. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.10.1-2ubuntu0.5
  7. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.0.3-1ubuntu0.4
  8. Upgrade

    Upgrade ubuntu/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.2-1ubuntu1.3
  9. Upgrade

    Upgrade debian/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.2-1+deb12u3
  10. Upgrade

    Upgrade debian/jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.6-1
  11. Upgrade

    Upgrade debian/jinja2 to a version that resolves this vulnerability.

    Fixed in 2.11.3-1+deb11u3Fixed in 3.1.2-1+deb12u3Fixed in 3.1.6-1
  12. Upgrade

    Upgrade alpine/py3-jinja2 to a version that resolves this vulnerability.

    Fixed in 3.1.6-r0
  13. Upgrade

    Upgrade to a fixed release to a version that resolves this vulnerability.

    Fixed in 3.1.6

Event History

Mar 5, 2025
CVE Published
via MITRE·08:40 PM
Data Sourced
via MITRE·08:40 PM
DescriptionWeakness
Advisory Published
via GitHub·08:40 PM
Data Sourced
via GitHub·08:40 PM
DescriptionWeaknessAffected Software
Data Sourced
via OSV·08:40 PM
DescriptionSeverityWeaknessAffected Software
Advisory Published
via GitHub·08:40 PM
Data Sourced
via Red Hat·09:01 PM
DescriptionSeverityAffected Software
Data Sourced
via NVD·09:15 PM
DescriptionSeverityWeakness
Mar 30, 2025
Event
via FIRST·12:00 AM
Apr 16, 2025
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software
May 1, 2025
Event
via NVD·01:15 AM
May 6, 2025
Updated
via IBM·12:00 AM
Affected Software
Aug 17, 2025
Updated
via IBM·12:00 AM
Affected Software
Sep 22, 2025
Data Sourced
via NVD·06:49 PM
RemedyAffected Software
Updated
via NVD·06:49 PM
Severity
May 14, 2026
Updated
via IBM·12:00 AM
Affected Software
Jun 17, 2026
Updated
via NVD·09:03 AM
Severity
Sep 26, 2026
Updated
via IBM·12:00 AM
Affected Software
Dec 3, 2026
Updated
via OSV·11:33 PM
Affected Software

Parent advisories

This vulnerability appears in the following advisories.

Peer vulnerabilities

Found alongside the following vulnerabilities.

Frequently Asked Questions

1

What is the severity of CVE-2025-27516?

CVE-2025-27516 is rated as a critical vulnerability due to its potential to enable arbitrary code execution.

2

How do I fix CVE-2025-27516?

To mitigate CVE-2025-27516, upgrade Jinja2 to version 3.1.6 or later.

3

Who is affected by CVE-2025-27516?

CVE-2025-27516 affects users of Jinja2 versions 3.1.5 and earlier.

4

What does CVE-2025-27516 allow an attacker to do?

CVE-2025-27516 allows an attacker to execute arbitrary Python code through controlled template content.

5

How can I identify if I'm vulnerable to CVE-2025-27516?

You can identify if you're vulnerable to CVE-2025-27516 by checking if you are using Jinja2 version 3.1.5 or earlier.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203