Twig may load a template outside a configured directory when using the filesystem loader
Published 30 Sept 2022 · Updated 10 Dec 2025
Affected packages
- Affected
- >=1.0.0 <1.44.7
- Fixed in
- 1.44.7
composer require twig/twig:^1.44.7- Affected
- >=2.0.0 <2.15.3
- Fixed in
- 2.15.3
composer require twig/twig:^2.15.3- Affected
- >=3.0.0 <3.4.3
- Fixed in
- 3.4.3
composer require twig/twig:^3.4.3Details
Description
When using the filesystem loader to load templates for which the name is a user input, it is possible to use the source or include statement to read arbitrary files from outside the templates directory when using a namespace like @somewhere/../some.file (in such a case, validation is bypassed).
Resolution
We fixed validation for such template names.
Even if the 1.x branch is not maintained anymore, a new version has been released.
Credits
We would like to thank Dariusz Tytko for reporting the issue and Fabien Potencier for fixing the issue.
Is GHSA-52m2-vc4m-jj33 in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected twig/twig, and gives you the command that fixes it.
References
- Linkgithub.com/twigphp/Twig/security/advisories/GHSA-52m2-vc4m-jj33
- Advisorynvd.nist.gov/vuln/detail/CVE-2022-39261
- Linkgithub.com/twigphp/Twig/commit/35f3035c5deb0041da7b84daf02dea074ddc7a0b
- Linkgithub.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2022-39261.yaml
- Packagegithub.com/twigphp/Twig
- Linklists.debian.org/debian-lts-announce/2022/10/msg00016.html
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/2OKRUHPVLIQVFPPJ2UWC3WV3WQO763NR
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/AUVTXMNPSZAHS3DWZEM56V5W4NPVR6L7
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/NWRFPZSR74SYVJKBTKTMYUK36IJ3SQJP
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/TW53TFJ6WWNXMUHOFACKATJTS7NIHVQE
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/WV5TNNJLGG536TJH6DLCIAAZZIPV2GUD
- Linklists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/YU4ZYX62H2NUAKKGUES4RZIM4KMTKZ7F
- Linksymfony.com/blog/twig-security-release-possibility-to-load-a-template-outside-a-configured-directory-when-using-the-filesystem-loader
- Linkwww.debian.org/security/2022/dsa-5248
- Linkwww.drupal.org/sa-core-2022-016
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.