CVE-2026-133772: Sandbox Tag Allow-List Bypass via the Branch of a `guard` Tag That Isn't Selected
The guard tag compiles only one of its branches, depending on whether a callable exists. The other branch was still parsed, though. The extends, use, macro and block tags in it registered their effects on the template. The sandbox doesn't see these tags, since that branch isn't compiled. A sandboxed template allowed to use guard could therefore extend a template, import blocks and define macros, while the policy doesn't allow these tags:
{% guard filter upper %}{% else %}{% extends "parent.html" %}{% endguard %}
The templates reached this way come from the loader of the sandbox, and they are sandboxed too.
What the branch that isn't selected registers on the parser is now discarded.
Affected Software
Event History
Frequently Asked Questions
Who is exposed to this issue?
Applications that render sandboxed Twig templates and allow the guard tag are exposed when their sandbox policy disallows extends, use, macro, or block tags. The issue affects parser-side effects from those tags when they appear in the guard branch that is not compiled.
What must an attacker be able to do to exploit it?
An attacker needs the ability to supply or control a sandboxed template that can use guard. They can place restricted tags such as extends in the branch that guard does not select, causing those tags to register effects despite not being seen by the sandbox policy.
Does this allow an attacker to load templates outside the sandbox?
No. Templates reached through this behavior come from the sandbox's configured loader and are themselves sandboxed.
What changes address the problem?
The fix discards parser registrations made by the guard branch that is not selected. Until the fix is applied, avoid allowing guard in sandboxed templates where extends, use, macro, or block are prohibited by policy.