CVE-2024-22195: Jinja2 Jinja Vulnerable To HTML Attribute Vulnerability

MODERATE
Advisory Identifier: GHSA-h5c8-rqwp-cp95
CVSS 5.4
CWE-79
Published
Advisory Summary

CVE-2024-22195 is a MODERATE (CVSS 5.4) jinja vulnerable to html attribute vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Jinja2 libraries in the PyPI ecosystem. The issue involves jinja vulnerable to html attribute injection when passing user input as keys to xmlattr filter. Remediation is available by upgrading affected packages to version 3.1.3.

CVE-2024-22195 at a Glance

CVE Identifier CVE-2024-22195
GHSA Identifier GHSA-h5c8-rqwp-cp95
Severity MODERATE
CVSS v3.1 Base Score 5.4
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Jinja2
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.4

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2024-22195

To remediate this vulnerability, upgrade all affected Jinja2 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

jinja2 fixed: 3.1.3
pip install jinja2>=3.1.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show jinja2

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2024-22195, inspect your installed packages using pip:

pip show jinja2

Analyze the terminal output to locate any version of Jinja2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.1.3), your application is affected.

Note: The pip show jinja2 command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Jinja2, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

The `xmlattr` filter in affected versions of Jinja accepts keys containing spaces. XML/HTML attributes cannot contain spaces, as each would then be interpreted as a separate attribute. If an application accepts keys (as opposed to only values) as user input, and renders these in pages that other users see as well, an attacker could use this to inject other attributes and perform XSS. Note that accepting keys as user input is not common or a particularly intended use case of the `xmlattr` filter, and an application doing so should already be verifying what keys are provided regardless of this fix.

CVE-2024-22195 Affected Jinja2 Versions

1 component(s)
Fixed Versions:
3.1.3
Product / Package Ecosystem Affected Versions Fixed Version
jinja2
PyPI
< 3.1.3
3.1.3

References

Frequently Asked Questions

What is CVE-2024-22195?
CVE-2024-22195 is a security vulnerability in Jinja2 involving Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Jinja2 versions are affected?
Affected versions include releases prior to 3.1.3 across affected packages: jinja2.
What version fixes CVE-2024-22195?
Upgrading to 3.1.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is jinja2 affected?
Yes, jinja2 is affected in releases prior to 3.1.3. Upgrade your dependency to 3.1.3 or later.
What is the CVSS score of CVE-2024-22195?
CVE-2024-22195 has a CVSS v3.1 base score of 5.4 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N.
What CWE is associated with CVE-2024-22195?
CVE-2024-22195 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check PyPI dependencies for CVE-2024-22195?
Run the dependency tree command: 'pip show jinja2'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-h5c8-rqwp-cp95",
  "modified" : "2025-11-04T16:48:33Z",
  "published" : "2024-01-11T15:20:48Z",
  "aliases" : [ "CVE-2024-22195" ],
  "summary" : "Jinja vulnerable to HTML attribute injection when passing user input as keys to xmlattr filter",
  "details" : "The `xmlattr` filter in affected versions of Jinja accepts keys containing spaces. XML/HTML attributes cannot contain spaces, as each would then be interpreted as a separate attribute. If an application accepts keys (as opposed to only values) as user input, and renders these in pages that other users see as well, an attacker could use this to inject other attributes and perform XSS. Note that accepting keys as user input is not common or a particularly intended use case of the `xmlattr` filter, and an application doing so should already be verifying what keys are provided regardless of this fix.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "jinja2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.1.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/security/advisories/GHSA-h5c8-rqwp-cp95"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-22195"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/commit/716795349a41d4983a9a4771f7d883c96ea17be7"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/pallets/jinja"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pallets/jinja/releases/tag/3.1.3"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/01/msg00010.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.debian.org/debian-lts-announce/2024/12/msg00009.html"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/5XCWZD464AJJJUBOO7CMPXQ4ROBC6JX2"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/DELCVUUYX75I5K4Q5WMJG4MUZJA6VAIP"
  }, {
    "type" : "WEB",
    "url" : "https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/O7YWRBX6JQCWC2XXCTZ55C7DPMGICCN3"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-01-11T15:20:48Z",
    "nvd_published_at" : "2024-01-11T03:15:11Z"
  }
}