{"id":"CVE-2026-46640","aliases":["CVE-2026-46640","GHSA-45vw-wh46-2vx8"],"related":[],"kind":"vulnerability","state":"published","title":"Twig: Arbitrary PHP code execution via `_self.(<string>)` macro-reference compilation","summary":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(<string>) and import-alias dynamic attribute syntax can concatenate an attacker-controlled string into a MacroReferenceExpression name without identifier validation, causing raw PHP to be emitted into the generated template source and executed at template-load time. This issue is fixed in version 3.26.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(<string>) and import-alias dynamic attribute syntax can concatenate an attacker-controlled string into a MacroReferenceExpression name without identifier validation, causing raw PHP to be emitted into the generated template source and executed at template-load time. This issue is fixed in version 3.26.0.","source":"cvelist"},{"lang":"en","text":"### Description\n\nThe `obj.(expr)` dynamic-attribute syntax (added in 3.15.0 as the replacement for the deprecated `attribute()` function) lets the attribute be an arbitrary expression. When the receiver is `_self` (or any `{% import %}` alias) and the parenthesised expression is a string literal, `DotExpressionParser` short-circuits to the macro-call path and concatenates the attacker-controlled string into a `MacroReferenceExpression` name with no identifier validation. `MacroReferenceExpression::compile()` then emits that name raw into the generated PHP source.\n\nAn attacker who can supply template source can inject arbitrary PHP into the compiled template and execute it at template-load time, before `checkSecurity()` is ever called. This is a complete bypass of `SandboxExtension`, including a globally-enabled sandbox with an empty `SecurityPolicy` allowlist.\n\n### Resolution\n\nThe parser now validates that the dynamic attribute resolves to a valid macro identifier before routing through `MacroReferenceExpression`, and the macro-reference compiler emits the name through a properly escaped path.\n\n### Credits\n\nTwig would like to thank Claude Mythos Preview (via Project Glasswing) for reporting the issue and providing the fix.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Twig es un lenguaje de plantillas para PHP. Desde la versión 3.15.0 hasta la 3.26.0, _self.([string]) y la sintaxis de atributo dinámico import-alias pueden concatenar una cadena controlada por un atacante en un nombre de MacroReferenceExpression sin validación de identificador, lo que provoca que se emita PHP sin procesar en el código fuente de la plantilla generada y se ejecute en el momento de la carga de la plantilla. Este problema está corregido en la versión 3.26.0.","source":"nvd"}],"published":"2026-05-21T21:31:08.000Z","modified":"2026-10-24T22:10:00.210Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","score":8.7,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","score":8.7,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","score":8.8,"rating":"HIGH"}],"cwes":["CWE-94"],"affected":[{"ranges":[{"version":">= 3.15.0, < 3.26.0","status":"affected"}],"vendor":"twigphp","product":"Twig","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"3.15.0","status":"affected","fixed":"3.26.0"}],"ecosystem":"Packagist","package":"twig/twig","purl":"pkg:composer/twig/twig","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"3.15.0","fixed":"3.26.0"}],"vendor":"symfony","product":"twig","cpe":"cpe:2.3:a:symfony:twig:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/twigphp/Twig/security/advisories/GHSA-45vw-wh46-2vx8","tags":["vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/twigphp/Twig/commit/324fa60545694fa6abe85ded9befcb82e1066bc2","tags":["patch","x-refsource-misc"],"sources":["cvelist","nvd"]},{"url":"https://github.com/twigphp/Twig/releases/tag/v3.26.0","tags":["release-notes","x-refsource-misc"],"sources":["cvelist","nvd"]},{"url":"https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-46640.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/twigphp/Twig","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/vladko312/extras/blob/main/CVE-2026-46640.py","tags":["web"],"sources":["ghsa"]},{"url":"https://symfony.com/cve-2026-46640","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"total","date":"2026-07-15T00:00:00.000Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-46640","url":"https://www.cve.org/CVERecord?id=CVE-2026-46640","licence":"CVE Terms of Use","modified":"2026-07-16T03:55:34.985Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-45vw-wh46-2vx8","url":"https://github.com/advisories/GHSA-45vw-wh46-2vx8","licence":"CC-BY-4.0","modified":"2026-09-10T03:51:04.496Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-46640","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-46640","licence":"Public domain","modified":"2026-10-24T22:10:00.210Z"}],"updatedAt":"2026-11-25T22:59:28.241Z","epss":{"score":0.00525,"percentile":0.45973,"date":"2026-12-01T12:00:22.000Z"}}