Read the docs

Twig skips autoescaping for variables named like import aliases

Priority LOW 13CWE-116Published · Updated

Key facts

Attack vector
Network
Privileges required
None
User interaction
Passive
Attack complexity
Low
Attack requirements
Present
Impact type
Cross-site scripting
Confidentiality · integrity · availability
None · None · None
Fix status
Fixed

Attack profile from CVSS 4.0 · CNA. Fix status from CNA. Impact type from CWE-79.

Summary

The Twig template engine, twig/twig from 0 before 3.31.0, prints some ordinary variables without escaping. The escaper treats a variable as safe when its name matches a macro import alias used in another block or macro, so its value is output raw. An unauthenticated remote attacker can exploit this for cross-site scripting (CWE-79) when a user interacts with a page that prints an attacker-controlled value.

Written with Claude Haiku 5.5 from the sources below · 2026-11-24

Description from the CNA

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.

Why it matters now

EPSS 0.00671 47th percentileScored 2026-11-30
Fix Fixed twig/twig (Twig): 3.31.0

SSVC decision points

Not available: CISA has not published SSVC decision points for this record.

Affected products

VendorProductAffected versionsFixed inStatusSource
Twigtwig/twigbefore 3.31.03.31.0Patch availableCNA
  • twig/twig VendorTwig Affected before 3.31.0 Fixed in 3.31.0 Patch available CNA

Remediation

Update twig/twig to 3.31.0, which removes the rule that marks these variables as safe.

Written with Claude Haiku 5.5 from the sources below · 2026-11-24

  • Fix · CNA twig/twig (Twig) Fixed in 3.31.0

Fixed in the same release

Records fixed by the same vendor advisory or release, as the CNA lists them.

  • Release ·

    twig/twig 3.31.0

    2 records Highest priority Priority LOW 2 LOW

    Other records, highest priority first

    • TI-2026-97286 Sandbox bypass in Twig guard tag lets templates use disallowed tagsPriority LOW 13

Timeline

  1. 2026-11-24 Threatist record created from CVE-2026-133771

References

  • TI-2026-97282 Sandbox bypass in Twig join filter exposes object properties CVSS 4.0MEDIUM 5.3
  • TI-2026-97281 Twig sandbox bypass through dynamic embed parent expressions CVSS 4.0MEDIUM 5.3
  • TI-2026-97279 Sandbox toString() policy bypass in Twig via assignments CVSS 4.0MEDIUM 5.3
  • TI-2026-97277 Sandbox toString policy bypass via is true test in Twig CVSS 4.0MEDIUM 5.3
  • TI-2026-97287 Unbounded converter cache in Twig markdown-extra exhausts memory CVSS 4.0LOW 2.3
  • TI-2026-97286 Sandbox bypass in Twig guard tag lets templates use disallowed tags CVSS 4.0LOW 2.3
See all 10 →

Sources

This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences