CVE-2026-49981: Twig Package Sandbox Filter Bypass Vulnerability

twig/twig Updated 02 Jul 2026

Summary

01/07/2026
Yes i
High
8.7

CVE-2026-49981: Description The per-template filter, tag and function allow-list check is compiled into the checkSecurity() method of each Template subclass and was invoked once from the constructor, gated by SandboxExtension::isSandbox... Affects twig/twig versions < 3.27.0. Fixed in 3.27.0. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Mobile apps built by Devnack Design, build and launch iOS and Android apps with a senior product team. From idea to store release Start a project

Background

Twig is a modern template engine for PHP, widely used for rendering templates in web applications. It provides a flexible and secure way to separate presentation logic from business logic. However, it has a vulnerability that affects its sandboxing feature, which is designed to restrict the execution of potentially dangerous code within templates.

Vulnerability Detail

The vulnerability arises from the way Twig handles security checks for filters, tags, and functions in sandboxed templates. The checks are performed during the construction of the template and cached for later use. If the sandbox state changes after the template is cached, the original security checks remain in effect, allowing potentially unsafe code to execute without proper validation. This can lead to unauthorized access or execution of malicious code, especially in environments where templates are shared between sandboxed and non-sandboxed contexts.

How To Fix

Minimum fixed version

3.27.0

This is the first release that contains the fix.

composer require twig/twig:3.27.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary workaround, avoid sharing the same Twig Environment instance between sandboxed and non-sandboxed renders. Ensure that templates are instantiated in a way that maintains their intended security context.

Conclusion

The CVE-2026-49981 vulnerability in the Twig package poses a significant risk due to its potential to bypass security checks in sandboxed environments. It is crucial to update to the patched version 3.27.0 or later to safeguard your applications. Additionally, using Vulert can help monitor and alert for such vulnerabilities in real-time.

See every vulnerability recorded for twig/twig →

Share this vulnerability

FAQ

The CVSS score of this vulnerability is 8.7, indicating a high severity level.

You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without needing to sign up.

Failing to address this vulnerability could allow attackers to execute unauthorized code within your application, potentially leading to data breaches or system compromise.

Yes, you can mitigate the risk by ensuring that sandboxed and non-sandboxed templates do not share the same Twig Environment instance.

The vulnerability was reported and fixed by Fabien Potencier, a key contributor to the Twig project.

Related vulnerabilities

Recent vulnerabilities recorded for twig/twig.

How To Fix

Minimum fixed version

3.27.0

This is the first release that contains the fix.

composer require twig/twig:3.27.0

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback