{"id":"CVE-2026-46640","aliases":["DEBIAN-CVE-2026-46640","EUVD-2026-44569","GHSA-45vw-wh46-2vx8","UBUNTU-CVE-2026-46640"],"status":"published","title":"Twig: Arbitrary PHP code execution via `_self.(\u003cstring\u003e)` macro-reference compilation","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","severity":{"version":"4.0","score":8.7,"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","level":"high","assessor":"cna","from":"cve"},"epss":{"day":"2026-11-10","score":0.00642,"percentile":0.5114,"model":"v2026.06.15"},"facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"cwes":["CWE-94"],"published":"2026-05-21T21:31:08Z","modified":"2026-10-28T02:31:12Z","fixes":[{"ecosystem":"Packagist","package":"twig/twig","fixed_in":["3.26.0"],"sources":["ghsa","osv"]},{"ecosystem":"Debian:13","package":"php-twig","fixed_in":["3.27.0-0+deb13u1"],"sources":["osv"]},{"ecosystem":"Debian:14","package":"php-twig","fixed_in":["3.26.0-1"],"sources":["osv"]}],"affected":[{"source":"ghsa","ecosystem":"Packagist","package":"twig/twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"3.15.0"},{"fixed":"3.26.0"}]}]},{"source":"osv","ecosystem":"Debian:13","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"3.27.0-0+deb13u1"}]}],"versions":["3.20.0-2","3.21.1-1","3.21.1-2","3.21.1-3","3.22.0-1","3.22.0-2","3.22.1-1","3.22.1-2","3.22.1-3","3.22.2-1","3.22.2-2","3.23.0-1","3.23.0-2","3.24.0-1","3.26.0-0+deb13u1","3.26.0-1"]},{"source":"osv","ecosystem":"Debian:14","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"3.26.0-1"}]}],"versions":["3.20.0-2","3.21.1-1","3.21.1-2","3.21.1-3","3.22.0-1","3.22.0-2","3.22.1-1","3.22.1-2","3.22.1-3","3.22.2-1","3.22.2-2","3.23.0-1","3.23.0-2","3.24.0-1"]},{"source":"osv","ecosystem":"Packagist","package":"twig/twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"3.15.0"},{"fixed":"3.26.0"}]}],"versions":["v3.15.0","v3.16.0","v3.17.0","v3.17.1","v3.18.0","v3.19.0","v3.20.0","v3.21.0","v3.21.1","v3.22.0","v3.22.1","v3.22.2","v3.23.0","v3.24.0","v3.25.0"]},{"source":"osv","ecosystem":"Ubuntu:Pro:20.04:LTS","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["2.11.3-2","2.12.1-1","2.12.2-1","2.12.3-1","2.12.5-1","2.12.5-1ubuntu0.1~esm1","2.12.5-1ubuntu0.1~esm2"]},{"source":"osv","ecosystem":"Ubuntu:Pro:22.04:LTS","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["3.3.2-1ubuntu3","3.3.4-1","3.3.6-1","3.3.7-1","3.3.8-2ubuntu4","3.3.8-2ubuntu4+esm1","3.3.8-2ubuntu4+esm2"]},{"source":"osv","ecosystem":"Ubuntu:Pro:24.04:LTS","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["3.7.0-1","3.7.1-1","3.8.0-2","3.8.0-2ubuntu0.1~esm1","3.8.0-2ubuntu1","3.8.0-2ubuntu1+esm1"]},{"source":"osv","ecosystem":"Ubuntu:25.10","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["3.20.0-2ubuntu1"]},{"source":"osv","ecosystem":"Ubuntu:26.10","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["3.23.0-2build7","3.27.1-1","3.28.0-1"]},{"source":"osv","ecosystem":"Ubuntu:Pro:26.04:LTS","package":"php-twig","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"}]}],"versions":["3.20.0-2ubuntu1","3.23.0-2build5","3.23.0-2build7","3.23.0-2ubuntu0.1~esm1"]}],"products":[{"vendor":"symfony","product":"twig"},{"vendor":"twigphp","product":"twig"}],"references":[{"url":"https://github.com/twigphp/Twig/security/advisories/GHSA-45vw-wh46-2vx8","tags":["x_refsource_CONFIRM","Vendor Advisory","advisory","web"]},{"url":"https://github.com/twigphp/Twig/commit/324fa60545694fa6abe85ded9befcb82e1066bc2","tags":["x_refsource_MISC","Patch","fix"]},{"url":"https://github.com/twigphp/Twig/releases/tag/v3.26.0","tags":["x_refsource_MISC","Release Notes","web"]},{"url":"https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-46640.yaml","tags":["web"]},{"url":"https://symfony.com/cve-2026-46640","tags":["web"]},{"url":"https://github.com/vladko312/extras/blob/main/CVE-2026-46640.py","tags":["web"]},{"url":"https://github.com/advisories/GHSA-45vw-wh46-2vx8"},{"url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/46xxx/CVE-2026-46640.json","tags":["advisory"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-46640","tags":["advisory"]},{"url":"https://security-tracker.debian.org/tracker/CVE-2026-46640","tags":["advisory"]},{"url":"https://github.com/twigphp/Twig","tags":["package"]},{"url":"https://ubuntu.com/security/CVE-2026-46640","tags":["report"]},{"url":"https://www.cve.org/CVERecord?id=CVE-2026-46640","tags":["report"]},{"url":"https://symfony.com/blog/cve-2026-46640-arbitrary-php-code-execution-via-self-string-macro-reference-compilation","tags":["report"]}],"sources":{"cve":[{"id":"CVE-2026-46640","title":"Twig: Arbitrary PHP code execution via `_self.(\u003cstring\u003e)` macro-reference compilation","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","status":"published","published":"2026-07-14T21:22:57.332Z","modified":"2026-07-16T03:55:34.985Z","cvss":[{"version":"4.0","score":8.7,"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","level":"high","assessor":"cna"}],"cwes":["CWE-94"],"updated_at":"2026-11-02T13:46:55.086623Z"}],"euvd":[{"id":"EUVD-2026-44569","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","status":"published","published":"2026-07-14T21:22:57Z","modified":"2026-07-16T03:55:34Z","cvss":[{"version":"4.0","score":8.7,"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","level":"high"}],"updated_at":"2026-11-02T18:19:52.35951Z"}],"ghsa":[{"id":"GHSA-45vw-wh46-2vx8","title":"Twig: Arbitrary PHP code execution via `_self.(\u003cstring\u003e)` macro-reference compilation","description":"### 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.","status":"published","published":"2026-05-21T21:31:08Z","modified":"2026-06-05T20:33:14Z","cvss":[{"version":"4.0","score":8.7,"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","level":"high"}],"cwes":["CWE-94"],"updated_at":"2026-11-02T14:40:17.745826Z"}],"nvd":[{"id":"CVE-2026-46640","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","status":"published","published":"2026-07-14T22:16:56.84Z","modified":"2026-10-24T22:10:00.21Z","cvss":[{"version":"4.0","score":8.7,"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/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X","level":"high","assessor":"secondary"},{"version":"3.1","score":8.8,"vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","level":"high","assessor":"primary"}],"cwes":["CWE-94"],"updated_at":"2026-11-02T14:12:29.879716Z"}],"osv":[{"id":"CVE-2026-46640","title":"Twig: Arbitrary PHP code execution via `_self.(\u003cstring\u003e)` macro-reference compilation","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","status":"published","published":"2026-07-14T21:22:57.332Z","modified":"2026-10-28T02:31:12.791159302Z","cvss":[{"version":"4.0","score":8.7,"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","level":"high"}],"cwes":["CWE-94"],"updated_at":"2026-11-02T15:45:06.231145Z"},{"id":"DEBIAN-CVE-2026-46640","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","status":"published","published":"2026-07-14T22:16:56.84Z","modified":"2026-10-25T09:47:28.728744842Z","cvss":[{"version":"3.1","score":8.8,"vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","level":"high"}],"updated_at":"2026-11-02T15:45:56.444225Z"},{"id":"GHSA-45vw-wh46-2vx8","title":"Twig: Arbitrary PHP code execution via `_self.(\u003cstring\u003e)` macro-reference compilation","description":"### 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.","status":"published","published":"2026-05-21T21:31:08Z","modified":"2026-09-10T03:51:04.496357989Z","cvss":[{"version":"4.0","score":8.7,"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","level":"high"}],"cwes":["CWE-94"],"updated_at":"2026-11-02T15:46:36.434231Z"},{"id":"UBUNTU-CVE-2026-46640","description":"Twig is a template language for PHP. From 3.15.0 until 3.26.0, _self.(\u003cstring\u003e) 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.","status":"published","published":"2026-07-14T22:16:00Z","modified":"2026-10-17T12:55:49.193382627Z","cvss":[{"version":"4.0","score":8.7,"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","level":"high"},{"version":"3.1","score":8.8,"vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","level":"high"}],"updated_at":"2026-11-02T16:56:30.797112Z"}]}}
