Skip to main content

CVE-2026-46634 — Vulnerability in twig/twig — CVE Details

MEDIUM

Twig: `template_from_string()` escapes a SourcePolicy-driven sandbox via synthesized template name

Published May 21, 2026Updated September 10, 2026Source: OSV

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (0.62%). Schedule for your next planned update.

Does your project use an affected twig/twig version?

Paste your composer.lock to check it for CVE-2026-46634 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my composer.lock

Summary

Description

When the sandbox is enabled selectively via SourcePolicyInterface (and not globally), a sandboxed template that is allowed to call template_from_string and include can render an arbitrary inner template with no security policy enforcement.

Environment::createTemplate() compiles the inner string under a synthesized name (__string_template__<hash>), so a name/path-based SourcePolicy returns false for it, and the inner template's checkSecurity() becomes a no-op. From a template the integrator believes is sandboxed, an attacker can use any tag/filter/function (including constant() to read secrets, or |map("system") to execute shell commands).

Resolution

This is a configuration trap rather than a code bug: there is no legitimate use case for exposing template_from_string to untrusted template authors, and propagating the parent sandbox state through template_from_string would require invasive changes to SourcePolicyInterface semantics with their own risks.

Starting with Twig 3.26.0, the documentation and the PHPDoc of StringLoaderExtension::templateFromString() explicitly warn against allowing template_from_string in a sandboxed environment (i.e. listing it in a SecurityPolicy allowed-functions list). Integrators using a SourcePolicyInterface MUST NOT allow template_from_string in their allowed functions; the safest option is not to register StringLoaderExtension at all when a sandbox is in use.

Credits

Twig would like to thank Claude Mythos Preview (via Project Glasswing) for reporting the issue.

Advisory Timeline

  • First published May 21, 2026 (189 days ago).
  • Last revised September 10, 2026 — 111 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

Composer
Update twig/twig to 3.26.0 or later
composer require "twig/twig:^3.26.0"

After upgrading, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (1)

Affects 1 ecosystem: Packagist (1).

PackageFixed In
twig/twig Packagist · Affected: v3.10.0, v3.10.1, v3.10.2, v3.10.3 (+28 more)3.26.0

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

  • CWE-693
    Protection Mechanism FailureMITRE

Frequently Asked Questions

What is CVE-2026-46634?
Twig: `template_from_string()` escapes a SourcePolicy-driven sandbox via synthesized template name. This vulnerability has been assigned a severity rating of MEDIUM.
How do I check if my project is affected by CVE-2026-46634?
CVE-2026-46634 affects twig/twig. It has a 0.6% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-46634 and 200,000+ other known vulnerabilities.

Severity & Exploitability

EPSS Score (30-day exploit probability)
0.62%
EPSS percentile: 43.8

This is a below-median EPSS score — only 43.8% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.

Also Known As

GHSA-24x9-r6q4-q93w

Related CVEs

  • CVE-2026-24425
    HIGH

    Twig: Possible sandbox bypass when using a source policy

  • CVE-2026-46640
    HIGH

    Twig: Arbitrary PHP code execution via `_self.(<string>)` macro-reference compilation

  • CVE-2026-46639
    HIGH

    Twig: Sandbox property and method bypass via object-destructuring assignment

  • CVE-2026-47732
    HIGH

    Twig: Sandbox: multiple `__toString()` policy bypasses via unguarded string coercion points

  • CVE-2026-47730
    LOW

    Twig: XSS in profiler HtmlDumper via unescaped template and profile names

  • CVE-2026-46628
    LOW

    Twig: The `spaceless` filter implicitly marks its output as safe

  • CVE-2026-48805
    LOW

    Twig: Sandbox state regression in deprecated internal wrappers in `src/Resources/core.php`

  • CVE-2026-46635
    LOW

    Twig: Sandbox property allowlist bypass via the `column` filter (array_column on objects)

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my composer.lock