The vulnerability in Twig (GHSA-529h-vh3j-85hq) was a sandbox bypass caused by improper caching of security checks. The checkSecurity() method was only called once when a template was first loaded and cached. If the sandbox settings were changed later (e.g., by enabling the sandbox for a subsequent request), the cached template would continue to use the old, less restrictive security policy, leading to a sandbox escape.
The fix was to introduce a new method, ensureSecurityChecked(), which is now called from several key template rendering functions. This ensures that the security policy is re-evaluated for every render, even for cached templates.
The identified vulnerable functions are the ones that were modified to call ensureSecurityChecked(). Before the patch, these functions were the entry points for exploiting the vulnerability, as they would render templates using the cached, and potentially outdated, security information. An attacker could exploit this by first having the application render a template in a non-sandboxed context, and then trigger a render of the same template in a sandboxed context, bypassing the sandbox restrictions.