Twig's sandbox lets you render templates written by people you don't fully trust, under a security policy that limits what they can reach. Before this fix, a sandboxed template could read entries of array-like objects (objects that implement ArrayAccess) without the policy being checked. Twig also called __isset() on objects before the security check instead of after it.

Who is affected

Apps that render untrusted templates with Twig's SandboxExtension, on twig/twig below 3.11.2, or 3.12.0 and later below 3.14.1. The attacker needs to be able to write templates. Apps that don't use the sandbox are not affected. Twig 1.x and 2.x are no longer maintained and stay vulnerable.

What to do

Update to 3.11.2 on the 3.11 branch, or to 3.14.1. Twig notes this is a backward compatibility break: access to array-like objects now goes through the sandbox's property policy, so your policy may need to allow properties that templates already use. On Twig 1.x or 2.x, move to 3.x. See Twig's advisory and the fix.

Reported by Jamie Schouten.