Incorrect Authorization Affecting twig/twig package, versions <3.27.0


Severity

Recommended
0.0
medium
0
10

CVSS assessment by Snyk's Security Team. Learn more

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Incorrect Authorization vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PHP-TWIGTWIG-17111522
  • published31 May 2026
  • disclosed27 May 2026
  • creditFabien Potencier

Introduced: 27 May 2026

CVE-2026-46636  (opens in a new tab)
CWE-863  (opens in a new tab)

How to fix?

Upgrade twig/twig to version 3.27.0 or higher.

Overview

twig/twig is a flexible, fast, and secure template language for PHP.

Affected versions of this package are vulnerable to Incorrect Authorization via cached template security decisions in the sandbox implementation. An attacker can bypass sandbox filter, tag, and function restrictions because the result of checkSecurity() is evaluated only once when a template instance is constructed and then cached in Environment::$loadedTemplates. Subsequent changes to sandbox state, security policy, or source-policy decisions are not re-evaluated for cached templates, allowing templates that were initially loaded outside the sandbox to execute filters, tags, and functions that would otherwise be prohibited by the current SecurityPolicy.

Note:

  1. Method, property, and __toString() restrictions are not affected, as those checks are enforced dynamically at runtime.

  2. Long-lived processes that reuse a single Environment across sandboxed and non-sandboxed renders are particularly affected, as templates loaded outside the sandbox can later be reused in sandboxed contexts without reapplying filter, tag, and function allow-list checks.

CVSS Base Scores

version 4.0
version 3.1