Sandbox Escape by math function in smarty
Key facts
- Attack vector
- Network
- Privileges required
- Low
- User interaction
- None
- Attack complexity
- Low
- Impact type
- —
- Confidentiality · integrity · availability
- High · High · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · NVD. Fix status from CNA and GitHub.
Summary
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic. Prior to versions 3.1.42 and 4.0.2, template authors could run arbitrary PHP code by crafting a malicious math string. If a math string was passed through as user provided data to the math function, external users could run arbitrary PHP code by crafting a malicious math string. Users should upgrade to version 3.1.42 or 4.0.2 to receive a patch.
Why it matters now
SSVC decision points
CISA ADP · SSVC 2.0.3
- Exploitation
- None
- Automatable
- No
- Technical impact
- Total
The decision (Track, Attend, Act) also depends on your mission and well-being impact; see CISA's SSVC guide.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| smarty-php | smarty | before 3.1.42; 4.0.0 to before 4.0.2 | 3.1.42, 4.0.2 | Patch available | CNA |
| — | smarty/smarty (Packagist) | before 3.1.42 | 3.1.42 | Patch available | GHSA-29gp-2c3m-3j6m |
| — | smarty/smarty (Packagist) | 4.0.0 to before 4.0.2 | 4.0.2 | Patch available | GHSA-29gp-2c3m-3j6m |
- smarty Vendorsmarty-php Affected before 3.1.42; 4.0.0 to before 4.0.2 Fixed in 3.1.42, 4.0.2 Patch available CNA
- smarty/smarty (Packagist) Vendor— Affected before 3.1.42 Fixed in 3.1.42 Patch available GHSA-29gp-2c3m-3j6m
- smarty/smarty (Packagist) Vendor— Affected 4.0.0 to before 4.0.2 Fixed in 4.0.2 Patch available GHSA-29gp-2c3m-3j6m
CPE configurations NVD · 6
| CPE | Versions | Role | Vendor |
|---|---|---|---|
| cpe:2.3:a:smarty:smarty:*:*:*:*:*:*:*:* | before 3.1.42; 4.0.0 to before 4.0.2 | Vulnerable | smarty-php |
| cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:* | 9.0 | Vulnerable | Debian |
| cpe:2.3:o:debian:debian_linux:10.0:*:*:*:*:*:*:* | 10.0 | Vulnerable | Debian |
| cpe:2.3:o:debian:debian_linux:11.0:*:*:*:*:*:*:* | 11.0 | Vulnerable | Debian |
| cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:* | 36 | Vulnerable | Fedoraproject |
| cpe:2.3:o:fedoraproject:fedora:37:*:*:*:*:*:*:* | 37 | Vulnerable | Fedoraproject |
- cpe:2.3:a:smarty:smarty:*:*:*:*:*:*:*:* Versions before 3.1.42; 4.0.0 to before 4.0.2 Vulnerable ·smarty-php
- cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:* Versions 9.0 Vulnerable ·Debian
- cpe:2.3:o:debian:debian_linux:10.0:*:*:*:*:*:*:* Versions 10.0 Vulnerable ·Debian
- cpe:2.3:o:debian:debian_linux:11.0:*:*:*:*:*:*:* Versions 11.0 Vulnerable ·Debian
- cpe:2.3:o:fedoraproject:fedora:36:*:*:*:*:*:*:* Versions 36 Vulnerable ·Fedoraproject
- cpe:2.3:o:fedoraproject:fedora:37:*:*:*:*:*:*:* Versions 37 Vulnerable ·Fedoraproject
Remediation
- Fix · CNA smarty (smarty-php) Fixed in 3.1.42, 4.0.2
- Fix · GHSA-29gp-2c3m-3j6m smarty/smarty (Packagist) Fixed in 3.1.42 Advisory →
- Fix · GHSA-29gp-2c3m-3j6m smarty/smarty (Packagist) Fixed in 4.0.2 Advisory →
Vendor assessments
Timeline
- 2026-10-02 Threatist record created from CVE-2021-29454
- 2026-10-03 Alias added: GHSA-29gp-2c3m-3j6m
References
Advisory 11
- https://github.com/smarty-php/smarty/security/advisories/GHSA-29gp-2c3m-3j6m
- https://github.com/smarty-php/smarty/releases/tag/v3.1.42
- https://github.com/smarty-php/smarty/releases/tag/v4.0.2
- https://packagist.org/packages/smarty/smarty
- https://www.smarty.net/docs/en/language.function.math.tpl
- [debian-lts-announce] 20220505 [SECURITY] [DLA 2995-1] smarty3 security update
- DSA-5151
- GLSA-202209-09
- FEDORA-2022-52154efd61
- FEDORA-2022-d5fc9dcdd7
- https://nvd.nist.gov/vuln/detail/CVE-2021-29454
Other 4
- https://github.com/FriendsOfPHP/security-advisories/blob/master/smarty/smarty/CVE-2021-29454.yaml
- https://github.com/smarty-php/smarty
- https://lists.fedoraproject.org/archives/list/[email protected]/message/BRAJVDRGCIY5UZ2PQHKDTT7RMKG6WJQQ
- https://lists.fedoraproject.org/archives/list/[email protected]/message/L777JIBIWJV34HS7LXPIDWASG7TT4LNI
More smarty-php Smarty vulnerabilities
- TI-2021-08070 Smarty before 3.1.39 allows code injection via an unexpected function name after a {function name= substring. CVSS 3.1CRITICAL 9.8
- TI-2009-01585 The smarty_function_math function in libs/plugins/function.math.php in Smarty 2.6.22… CVSS 2.0HIGH 10.0
- TI-2006-06846 PHP remote file inclusion vulnerability in libs/Smarty.class.php in Smarty 2.6.9 allows… CVSS 3.1CRITICAL 9.8
- TI-2022-11764 PHP Code Injection by malicious block or filename in Smarty CVSS 3.1HIGH 8.8
- TI-2017-14689 Smarty 3 before 3.1.32 is vulnerable to a PHP code injection when calling fetch() or… CVSS 3.0CRITICAL 9.8
- TI-2010-04450 Smarty before 3.0.0 beta 7 does not properly handle the <?php and ?> tags, which has… CVSS 2.0HIGH 10.0
Sources
- CVE-2021-29454 · CVE Program
- CVE-2021-29454 · NVD
- FIRST EPSS
- GHSA-29gp-2c3m-3j6m · GitHub Advisory Database · CC BY 4.0
- CVE-2021-29454 · Red Hat security data · CC BY 4.0
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences