Summary
CVE-2026-82531 is a code injection vulnerability in the Smarty PHP template engine affecting versions before 4.5.8 and 5.x before 5.8.5. The flaw occurs because the top-level nocache_hash value is never restored when a template is rendered through the extends:/multi-component inheritance path, leaving it null and allowing attacker-controlled template output to forge a {nocache} marker. This lets an attacker inject raw PHP code into the generated template cache file, resulting in remote code execution on next render — rated 9.2 (Critical).
Technical details
- Root cause: Smarty’s cache-compiler fails to restore the top-level
nocache_hashduringextends:/multi-component template inheritance, leaving itnullinstead of a unique per-compile value. - Trigger condition: An attacker who can influence template content or variables rendered through inheritance (
extends:resource or multi-component templates) can forge a{nocache}marker because the hash used to validate legitimate nocache blocks is missing/predictable (null). - Attack vector: Network — exploitable in any application that compiles and caches Smarty templates where template content, variables, or includes can be influenced by untrusted input (e.g., user-supplied template fragments, CMS theming, multi-tenant templating).
- Impact: Once the forged nocache marker is accepted, arbitrary raw PHP is written into the compiled/cached template file. On the next request that renders the cached template, the injected PHP executes in the context of the web application — leading to full remote code execution, and compromising confidentiality, integrity, and availability of the host.
- Vulnerability class: CWE-94 (Improper Control of Generation of Code / Code Injection).
- Reporter: Credited to security researcher MegaManSec.
Affected software
- Smarty (
smarty/smarty) versions 0 up to (but not including) 4.5.8 - Smarty (
smarty/smarty) versions 5.0.0 up to (but not including) 5.8.5
Severity
- CVSS score (as rated by IONIX/reporting source): 9.2 (Critical)
- CVSS v3.1 vector (per CVE record):
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H(Base score 8.1, High) - CWE: CWE-94 — Improper Control of Generation of Code (‘Code Injection’)
Mitigation and recommended actions
- Immediate: Upgrade to Smarty 4.5.8 (4.x branch) or Smarty 5.8.5 (5.x branch), both of which restore the
nocache_hashcorrectly duringextends:/multi-component template inheritance and prevent forged nocache markers from being written to the cache. - If immediate patching is not possible:
- Disable or avoid use of template caching (
caching) in combination withextends:/multi-component template inheritance for any template whose content or variables can be influenced by untrusted or external input. - Restrict the ability of untrusted users to author, upload, or otherwise influence template content, includes, or variables rendered through inheritance.
- Audit and, where necessary, purge existing compiled/cached template files to remove any previously injected code, then regenerate caches only after patching.
- Apply the principle of least privilege to the web server process so that even if PHP code is injected into a cache file, its execution impact is constrained.
- Disable or avoid use of template caching (

