CVE-2021-26120

9.8 CRITICAL

📋 TL;DR

CVE-2021-26120 is a critical code injection vulnerability in Smarty template engine that allows attackers to execute arbitrary PHP code via specially crafted {function name=} tags. This affects all applications using Smarty templates before version 3.1.39. The vulnerability can lead to complete system compromise.

💻 Affected Systems

Products:
  • Smarty PHP Template Engine
Versions: All versions before 3.1.39
Operating Systems: All operating systems running PHP
Default Config Vulnerable: ⚠️ Yes
Notes: Vulnerability exists in the core Smarty template parsing engine. Any application using Smarty templates with user-controlled input in function names is vulnerable.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Remote code execution leading to complete server takeover, data exfiltration, and lateral movement within the network.

🟠

Likely Case

Web application compromise allowing attackers to execute arbitrary code, access sensitive data, and potentially pivot to other systems.

🟢

If Mitigated

Limited impact with proper input validation and output encoding, though the vulnerability remains exploitable if templates accept user input.

🌐 Internet-Facing: HIGH - Web applications using Smarty templates are directly exposed to exploitation attempts.
🏢 Internal Only: MEDIUM - Internal applications are still vulnerable but require internal access or compromised credentials.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

Exploitation requires user input to reach the template engine's function name parsing. Public proof-of-concept code exists demonstrating the vulnerability.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 3.1.39 and later

Vendor Advisory: https://github.com/smarty-php/smarty/blob/master/CHANGELOG.md

Restart Required: No

Instructions:

1. Update Smarty to version 3.1.39 or later using composer: 'composer require smarty/smarty:^3.1.39' 2. Replace the Smarty library files in your application with the patched version. 3. Clear any template caches.

🔧 Temporary Workarounds

Input Validation for Template Variables

all

Implement strict input validation for any user-controlled data that reaches Smarty template functions

Disable Template Caching

all

Temporarily disable Smarty template caching to prevent persistent exploitation

$smarty->caching = 0;

🧯 If You Can't Patch

  • Implement WAF rules to block suspicious {function name=} patterns in HTTP requests
  • Isolate affected applications behind reverse proxies with strict input filtering

🔍 How to Verify

Check if Vulnerable:

Check your composer.json or Smarty library files for version number. Versions below 3.1.39 are vulnerable.

Check Version:

php -r "require_once 'Smarty.class.php'; $smarty = new Smarty(); echo 'Version: ' . Smarty::SMARTY_VERSION;"

Verify Fix Applied:

Verify Smarty version is 3.1.39 or higher. Test with a safe payload to confirm the vulnerability is patched.

📡 Detection & Monitoring

Log Indicators:

  • Unusual {function name=} patterns in application logs
  • PHP execution errors from template parsing
  • Unexpected file creation or modification

Network Indicators:

  • HTTP requests containing crafted {function name=} payloads
  • Unusual outbound connections from web server

SIEM Query:

web_access_logs | where url contains "{function name=" or url contains "%7Bfunction%20name%3D"

🔗 References

📤 Share & Export