The SentinelOne Annual Threat Report - A Defenders Guide from the FrontlinesThe SentinelOne Annual Threat ReportGet the Report
Experiencing a Breach?Blog
Get StartedContact Us
SentinelOne
  • Platform
    Platform Overview
    • Singularity Platform
      Welcome to Integrated Enterprise Security
    • AI for Security
      Leading the Way in AI-Powered Security Solutions
    • Securing AI
      Accelerate AI Adoption with Secure AI Tools, Apps, and Agents.
    • How It Works
      The Singularity XDR Difference
    • Singularity Marketplace
      One-Click Integrations to Unlock the Power of XDR
    • Pricing & Packaging
      Comparisons and Guidance at a Glance
    Data & AI
    • Purple AI
      Accelerate SecOps with Generative AI
    • Singularity Hyperautomation
      Easily Automate Security Processes
    • AI-SIEM
      The AI SIEM for the Autonomous SOC
    • Singularity Data Lake
      AI-Powered, Unified Data Lake
    • Singularity Data Lake for Log Analytics
      Seamlessly Ingest Data from On-Prem, Cloud or Hybrid Environments
    Endpoint Security
    • Singularity Endpoint
      Autonomous Prevention, Detection, and Response
    • Singularity XDR
      Native & Open Protection, Detection, and Response
    • Singularity RemoteOps Forensics
      Orchestrate Forensics at Scale
    • Singularity Threat Intelligence
      Comprehensive Adversary Intelligence
    • Singularity Vulnerability Management
      Application & OS Vulnerability Management
    • Singularity Identity
      Identity Threat Detection and Response
    Cloud Security
    • Singularity Cloud Security
      Block Attacks with an AI-Powered CNAPP
    • Singularity Cloud Native Security
      Secure Cloud and Development Resources
    • Singularity Cloud Workload Security
      Real-Time Cloud Workload Protection Platform
    • Singularity Cloud Data Security
      AI-Powered Threat Detection for Cloud Storage
    • Singularity Cloud Security Posture Management
      Detect and Remediate Cloud Misconfigurations
    Securing AI
    • Prompt Security
      Secure AI Tools Across Your Enterprise
  • Why SentinelOne?
    Why SentinelOne?
    • Why SentinelOne?
      Cybersecurity Built for What’s Next
    • Our Customers
      Trusted by the World’s Leading Enterprises
    • Industry Recognition
      Tested and Proven by the Experts
    • About Us
      The Industry Leader in Autonomous Cybersecurity
    Compare SentinelOne
    • Arctic Wolf
    • Broadcom
    • CrowdStrike
    • Cybereason
    • Microsoft
    • Palo Alto Networks
    • Sophos
    • Splunk
    • Trellix
    • Trend Micro
    • Wiz
    Verticals
    • Energy
    • Federal Government
    • Finance
    • Healthcare
    • Higher Education
    • K-12 Education
    • Manufacturing
    • Retail
    • State and Local Government
  • Services
    Managed Services
    • Managed Services Overview
      Wayfinder Threat Detection & Response
    • Threat Hunting
      World-Class Expertise and Threat Intelligence
    • Managed Detection & Response
      24/7/365 Expert MDR Across Your Entire Environment
    • Incident Readiness & Response
      DFIR, Breach Readiness, & Compromise Assessments
    Support, Deployment, & Health
    • Technical Account Management
      Customer Success with Personalized Service
    • SentinelOne GO
      Guided Onboarding & Deployment Advisory
    • SentinelOne University
      Live and On-Demand Training
    • Services Overview
      Comprehensive Solutions for Seamless Security Operations
    • SentinelOne Community
      Community Login
  • Partners
    Our Network
    • MSSP Partners
      Succeed Faster with SentinelOne
    • Singularity Marketplace
      Extend the Power of S1 Technology
    • Cyber Risk Partners
      Enlist Pro Response and Advisory Teams
    • Technology Alliances
      Integrated, Enterprise-Scale Solutions
    • SentinelOne for AWS
      Hosted in AWS Regions Around the World
    • Channel Partners
      Deliver the Right Solutions, Together
    • SentinelOne for Google Cloud
      Unified, Autonomous Security Giving Defenders the Advantage at Global Scale
    • Partner Locator
      Your Go-to Source for Our Top Partners in Your Region
    Partner Portal→
  • Resources
    Resource Center
    • Case Studies
    • Data Sheets
    • eBooks
    • Reports
    • Videos
    • Webinars
    • Whitepapers
    • Events
    View All Resources→
    Blog
    • Feature Spotlight
    • For CISO/CIO
    • From the Front Lines
    • Identity
    • Cloud
    • macOS
    • SentinelOne Blog
    Blog→
    Tech Resources
    • SentinelLABS
    • Ransomware Anthology
    • Cybersecurity 101
  • About
    About SentinelOne
    • About SentinelOne
      The Industry Leader in Cybersecurity
    • Investor Relations
      Financial Information & Events
    • SentinelLABS
      Threat Research for the Modern Threat Hunter
    • Careers
      The Latest Job Opportunities
    • Press & News
      Company Announcements
    • Cybersecurity Blog
      The Latest Cybersecurity Threats, News, & More
    • FAQ
      Get Answers to Our Most Frequently Asked Questions
    • DataSet
      The Live Data Platform
    • S Foundation
      Securing a Safer Future for All
    • S Ventures
      Investing in the Next Generation of Security, Data and AI
  • Pricing
Get StartedContact Us
CVE Vulnerability Database
Vulnerability Database/CVE-2021-29454

CVE-2021-29454: Smarty Template Engine RCE Vulnerability

CVE-2021-29454 is a remote code execution flaw in Smarty template engine for PHP that allows attackers to execute arbitrary code via malicious math strings. This article covers technical details, affected versions, and patches.

Published: February 25, 2026

CVE-2021-29454 Overview

CVE-2021-29454 is a Code Injection vulnerability affecting Smarty, a widely-used template engine for PHP that facilitates 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. When a math string is passed through as user-provided data to the {math} function, external users can achieve remote code execution by exploiting insufficient input validation in the mathematical expression parser.

Critical Impact

This vulnerability allows authenticated attackers to execute arbitrary PHP code on the server through crafted math strings, potentially leading to complete system compromise, data theft, and server takeover.

Affected Products

  • Smarty versions prior to 3.1.42
  • Smarty versions 4.x prior to 4.0.2
  • Debian Linux 9.0, 10.0, and 11.0
  • Fedora 36 and 37

Discovery Timeline

  • 2022-01-10 - CVE-2021-29454 published to NVD
  • 2024-11-21 - Last updated in NVD database

Technical Details for CVE-2021-29454

Vulnerability Analysis

The vulnerability exists in the {math} function within Smarty's template engine. This function is designed to allow mathematical calculations within templates, but insufficient validation of the mathematical expression input allows attackers to inject arbitrary PHP code. The {math} function uses eval() internally to process mathematical expressions, and prior to the patch, the whitelist of allowed functions was incomplete, enabling code injection through crafted inputs.

The attack requires the attacker to have the ability to provide input to a template's {math} function, either as a template author or through user-supplied data that flows into the math parameter. Once exploited, the attacker gains the ability to execute arbitrary PHP code with the privileges of the web server process.

Root Cause

The root cause is an Injection vulnerability (CWE-74) in the {math} function's expression parser. The function failed to properly sanitize and validate input before passing it to PHP's evaluation functions. The whitelist of allowed mathematical functions was incomplete, allowing attackers to bypass restrictions and inject malicious code through unfiltered function calls within math expressions.

Attack Vector

The attack can be conducted over the network without user interaction. An authenticated attacker with low privileges who can influence template input can craft a malicious mathematical expression containing PHP code. When the template engine processes the {math} function with this malicious input, the injected code executes on the server. This is particularly dangerous when user-supplied data is passed to the math function without proper sanitization.

The following patch from the security fix shows the expanded whitelist of allowed mathematical functions:

php
             'int'   => true,
             'abs'   => true,
             'ceil'  => true,
+            'acos'   => true,
+            'acosh'   => true,
             'cos'   => true,
+            'cosh'   => true,
+            'deg2rad'   => true,
+            'rad2deg'   => true,
             'exp'   => true,
             'floor' => true,
             'log'   => true,

Source: GitHub Commit 215d81a9

Detection Methods for CVE-2021-29454

Indicators of Compromise

  • Unusual PHP process activity originating from web server processes
  • Unexpected outbound network connections from the web application server
  • Suspicious template files containing complex or obfuscated {math} expressions
  • Web server error logs showing PHP execution errors related to the Smarty template engine
  • Abnormal file system modifications in web directories

Detection Strategies

  • Monitor web application logs for requests containing suspicious mathematical expressions or encoded payloads targeting template parameters
  • Implement Web Application Firewall (WAF) rules to detect and block code injection patterns in request parameters
  • Use file integrity monitoring to detect unauthorized changes to Smarty template files
  • Deploy runtime application self-protection (RASP) solutions to detect eval-based code execution attempts

Monitoring Recommendations

  • Enable detailed logging for the Smarty template engine to capture all {math} function invocations
  • Monitor for unusual PHP function calls and process spawning from the web server context
  • Implement alerting for outbound network connections from application servers that don't match expected patterns
  • Review and audit template files periodically for suspicious content

How to Mitigate CVE-2021-29454

Immediate Actions Required

  • Upgrade Smarty to version 3.1.42 or later for the 3.x branch
  • Upgrade Smarty to version 4.0.2 or later for the 4.x branch
  • Review all templates for user-controlled input flowing into {math} functions
  • Implement strict input validation for any data passed to template functions
  • Consider disabling the {math} function if not required by your application

Patch Information

Security patches are available from the official Smarty project. The fix expands the whitelist of allowed functions in the math expression parser and improves input sanitization. Patches can be obtained from:

  • Smarty v3.1.42 Release
  • Smarty v4.0.2 Release
  • GitHub Security Advisory GHSA-29gp-2c3m-3j6m

For Debian users, refer to DSA-5151 and the Debian LTS Announcement. Gentoo users should consult GLSA 202209-09.

Workarounds

  • Avoid using the {math} function with user-supplied input until patching is possible
  • Implement strict whitelist validation for any mathematical expressions before they reach Smarty templates
  • Use security plugins or custom pre-processors to sanitize template input
  • Isolate the web application in a containerized environment to limit the impact of potential exploitation
bash
# Update Smarty via Composer
composer require smarty/smarty:^3.1.42
# Or for Smarty 4.x
composer require smarty/smarty:^4.0.2

# Verify the installed version
composer show smarty/smarty | grep versions

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

  • Vulnerability Details
  • TypeRCE

  • Vendor/TechSmarty

  • SeverityHIGH

  • CVSS Score8.8

  • EPSS Probability0.64%

  • Known ExploitedNo
  • CVSS Vector
  • CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
  • Impact Assessment
  • ConfidentialityLow
  • IntegrityNone
  • AvailabilityHigh
  • CWE References
  • CWE-74
  • Technical References
  • GitHub Release v3.1.42

  • GitHub Release v4.0.2

  • GitHub Security Advisory GHSA-29gp-2c3m-3j6m

  • Debian LTS Announcement 2022-05

  • Fedora Package Announcement

  • Fedora Package Announcement

  • Packagist Smarty Package Page

  • Gentoo GLSA 2022-09

  • Debian Security Advisory DSA-5151
  • Vendor Resources
  • GitHub Commit Update

  • Smarty Documentation on Math Function
  • Related CVEs
  • CVE-2024-35226: Smarty Template Engine RCE Vulnerability

  • CVE-2021-26120: Smarty Template Engine RCE Vulnerability

  • CVE-2021-26119: Smarty Sandbox Escape Vulnerability
Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the World’s Most Advanced Cybersecurity Platform

See how our intelligent, autonomous cybersecurity platform can protect your organization now and into the future.

Try SentinelOne
  • Get Started
  • Get a Demo
  • Product Tour
  • Why SentinelOne
  • Pricing & Packaging
  • FAQ
  • Contact
  • Contact Us
  • Customer Support
  • SentinelOne Status
  • Language
  • Platform
  • Singularity Platform
  • Singularity Endpoint
  • Singularity Cloud
  • Singularity AI-SIEM
  • Singularity Identity
  • Singularity Marketplace
  • Purple AI
  • Services
  • Wayfinder TDR
  • SentinelOne GO
  • Technical Account Management
  • Support Services
  • Verticals
  • Energy
  • Federal Government
  • Finance
  • Healthcare
  • Higher Education
  • K-12 Education
  • Manufacturing
  • Retail
  • State and Local Government
  • Cybersecurity for SMB
  • Resources
  • Blog
  • Labs
  • Case Studies
  • Videos
  • Product Tours
  • Events
  • Cybersecurity 101
  • eBooks
  • Webinars
  • Whitepapers
  • Press
  • News
  • Ransomware Anthology
  • Company
  • About Us
  • Our Customers
  • Careers
  • Partners
  • Legal & Compliance
  • Security & Compliance
  • Investor Relations
  • S Foundation
  • S Ventures

©2026 SentinelOne, All Rights Reserved.

Privacy Notice Terms of Use

English