Security
Headlines
HeadlinesLatestCVEs

Headline

GHSA-52m2-vc4m-jj33: Twig may load a template outside a configured directory when using the filesystem loader

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.

ghsa
#vulnerability#git#php

Twig may load a template outside a configured directory when using the filesystem loader

High severity GitHub Reviewed Published Sep 30, 2022 in twigphp/Twig • Updated Sep 30, 2022

Package

composer twig/twig (Composer)

Affected versions

>= 1.0.0, < 1.44.7

>= 2.0.0, < 2.15.3

>= 3.0.0, < 3.4.3

Patched versions

1.44.7

2.15.3

3.4.3

Description

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.

References

  • GHSA-52m2-vc4m-jj33
  • https://nvd.nist.gov/vuln/detail/CVE-2022-39261
  • twigphp/Twig@35f3035
  • https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2022-39261.yaml
  • https://symfony.com/blog/twig-security-release-possibility-to-load-a-template-outside-a-configured-directory-when-using-the-filesystem-loader
  • https://www.drupal.org/sa-core-2022-016

fabpot published the maintainer security advisory

Sep 28, 2022

Severity

High

7.5

/ 10

CVSS base metrics

Attack vector

Network

Attack complexity

Low

Privileges required

None

User interaction

None

Scope

Unchanged

Confidentiality

High

Integrity

None

Availability

None

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N

Weaknesses

CWE-22

CVE ID

CVE-2022-39261

GHSA ID

GHSA-52m2-vc4m-jj33

Source code

twigphp/Twig

Checking history

See something to contribute? Suggest improvements for this vulnerability.

Related news

Ubuntu Security Notice USN-5947-1

Ubuntu Security Notice 5947-1 - Fabien Potencier discovered that Twig was not properly enforcing sandbox policies when dealing with objects automatically cast to strings by PHP. An attacker could possibly use this issue to expose sensitive information. This issue was only fixed in Ubuntu 16.04 ESM and Ubuntu 18.04 ESM. Marlon Starkloff discovered that Twig was not properly enforcing closure constraints in some of its array filtering functions. An attacker could possibly use this issue to execute arbitrary code. This issue was only fixed in Ubuntu 20.04 ESM.

CVE-2022-39261: security #cve- Fix a security issue on filesystem loader (possibility… · twigphp/Twig@35f3035

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.