Skip to content
Laskyr

twig/twig security advisory

CVE-2026-133771: Missing autoescaping for a variable named like a macro import alias of another scope in twig/twig

CVE-2026-133771 is a low-severity XSS vulnerability in the PHP package twig/twig (CVSS 2.3), published 24 November 2026. It is fixed in 3.31.0; earlier versions are affected. It can be exploited without an account.

published 2026-11-24

2.3 Low CVSS 4.0

Fixed in twig/twig 3.31.0

This XSS issue affects twig/twig versions >= 1.0.0, < 3.31.0. Upgrade to the fixed version for your release line (3.31.0). The newest release, 3.31.1, is not affected.

Affected versions
>= 1.0.0, < 3.31.0
Fixed in
3.31.0
Newest release
3.31.1
Type
Cross-site scripting (XSS)
CWE-79, CWE-116
Exploited in the wild
Not on the CISA KEV list
checked 2026-11-29

Is your twig/twig version affected?

Run composer show twig/twig in your project, then enter the version. We check it against this and every other known twig/twig advisory.

Who can exploit CVE-2026-133771

Your app is only exposed if it uses the affected part of twig/twig. The advisory below says which part that is. If you are not sure, upgrade anyway: it costs less than finding out.

Technical details

Weakness

Cross-site scripting (XSS) CWE-79CWE-116

Attacker-controlled text reaches a page without being made safe, so the browser runs it as script.

The script acts in the session of whoever views the page, which matters most when that is an administrator.

General description of this issue type. The advisory below covers this bug.

CVSS 4.0 breakdown

Attack vector
Network (remote)
Attack complexity
Low
Attack requirements
Specific conditions
Privileges required
None
User interaction
Passive
Confidentiality impact
None
Integrity impact
None
Availability impact
None

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

How to fix CVE-2026-133771 in twig/twig

  1. Find the installed version: composer show twig/twig. If you never required it yourself, composer why twig/twig shows which package pulls it in.
  2. Update it: composer update twig/twig --with-all-dependencies. You need 3.31.0 or newer.
  3. If Composer will not go that high, your composer.json constraint is holding it back. Widen it (for example "twig/twig": "^3.31.0" if you can take that version), or upgrade the package that requires it.
  4. Run composer audit. It reads the same advisory data and should no longer list CVE-2026-133771.
  5. Commit composer.lock and deploy it. On the server, run composer install --no-dev from the lock file, not composer update.

If you cannot upgrade yet

General hardening for XSS issues while the upgrade waits. None of it replaces the fix.

Is your project exposed to CVE-2026-133771?

Check the one package here, or check everything your project installs at once.

  1. Check twig/twig Enter your installed version and compare it with every known twig/twig advisory. Check my version
  2. Check your whole composer.lock The free checker compares every locked package with the same advisory data composer audit uses. Check composer.lock

The CVE-2026-133771 advisory

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.

Description from the CVE record, via the NVD entry for CVE-2026-133771. Advisory title: “CVE-2026-133771: Missing autoescaping for a variable named like a macro import alias of another scope”.

References

Other twig/twig advisories

Related

Need help patching or upgrading? Laskyr does PHP and Laravel security fixes and upgrades. Tell us what you run and we reply with a plan and a price.

Ask about a fix

Where this data comes from

First hour checklist

If the site was just hacked, read the emergency kit before you delete files. The page is free. Email is optional.

Read the emergency kit

The box is optional and does not affect the kit. Privacy policy.