All vulnerabilities

Packagist

CVE-2026-133771

Missing autoescaping for a variable named like a macro import alias of another scope

Severity
Low 2.3
Published
24 Nov 2026
Last changed
24 Nov 2026
Added to UpHeron
24 Nov 2026
Fixed in
3.31.0
Weakness
Cross-site scripting (CWE-79)Improper output encoding (CWE-116)
Attack
Over the network · Only under certain conditions · No login needed · Needs someone to view a page or file
CVSS vector
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N
Sources
CVE Program

Description

The escaper considered x.attr, x['key'] and x.method() safe whenever {% import ... as x %} appeared anywhere in the template. Macro calls haven't needed this rule since Twig 3.0. It only matched ordinary variables that have the name of an alias imported in another block or macro, and printed them without escaping:

{% block header %}{% import _self as item %}{{ item.hello() }}{% endblock %} {% block content %}{% for item in items %}{{ item.body }}{% endfor %}{% endblock %}

Here, item.body is printed raw. This leads to XSS when the value comes from an attacker. The same happens with an import in a macro and an argument of the same name in another macro. It also happens with a template-level import placed after the block that uses the name.

The rule is removed. Macro calls through an alias are still considered safe.

From the CVE Program.

Affected software

SoftwareAffected versions
twig/twigPackagist · osv:Packagist:twig/twig
  • Every version before 3.31.0

About twig/twig

Monthly downloads (Packagist)
14,503,338Packagist, 24 Nov 2026
Total downloads (Packagist)
517,678,663Packagist, 24 Nov 2026

References

  • CVE.org https://www.cve.org/CVERecord?id=CVE-2026-133771