/

CVE-2026-82531

Severity:

HIGH RISK

(8.1)

PHP Code Injection (CWE-94) in Smarty Template Cache

CVE-2026-82531

Awaiting Analysis

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

HIGH RISK

(8.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A code injection vulnerability in Smarty can cause attacker-controlled template data to be written into regenerated PHP cache files when template inheritance is used incorrectly.

If an attacker can supply crafted assigned data that reaches the affected caching path, arbitrary PHP code may execute when the generated cache is included, potentially resulting in remote code execution.

A code injection vulnerability in Smarty can cause attacker-controlled template data to be written into regenerated PHP cache files when template inheritance is used incorrectly.

If an attacker can supply crafted assigned data that reaches the affected caching path, arbitrary PHP code may execute when the generated cache is included, potentially resulting in remote code execution.

Affected context

The vulnerability may occur in Smarty applications that use extends: or multi-component template inheritance and regenerate PHP template cache files from assigned data. The risk depends on whether an attacker can influence the relevant template data and whether generated cache files are later included by the application.

The vulnerability may occur in Smarty applications that use extends: or multi-component template inheritance and regenerate PHP template cache files from assigned data. The risk depends on whether an attacker can influence the relevant template data and whether generated cache files are later included by the application.

Exploit preconditions

  • Attack surface: Smarty template rendering and PHP cache generation
  • Required access: Ability to influence assigned template data that reaches the affected inheritance path
  • Trigger point: Regeneration and subsequent inclusion of a PHP template cache file
  • Why exploitation is possible: The top-level nocache_hash value may remain null, allowing a forged Smarty nocache marker in assigned data to be copied into generated PHP code
  • Attack surface: Smarty template rendering and PHP cache generation
  • Required access: Ability to influence assigned template data that reaches the affected inheritance path
  • Trigger point: Regeneration and subsequent inclusion of a PHP template cache file
  • Why exploitation is possible: The top-level nocache_hash value may remain null, allowing a forged Smarty nocache marker in assigned data to be copied into generated PHP code

Why this happens

The underlying bug is an incomplete restoration of template-inheritance state during cache regeneration. When the top-level nocache_hash value is not restored, attacker-influenced data containing a specially formed internal marker may be copied verbatim into a PHP cache file.

This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because data intended for template content crosses into generated executable PHP without adequate separation or validation.

The underlying bug is an incomplete restoration of template-inheritance state during cache regeneration. When the top-level nocache_hash value is not restored, attacker-influenced data containing a specially formed internal marker may be copied verbatim into a PHP cache file.

This behavior maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), because data intended for template content crosses into generated executable PHP without adequate separation or validation.

Potential impact

  • An attacker may execute arbitrary PHP code in the application process
  • Application secrets and configuration data could be exposed
  • Application data may be modified, deleted, or poisoned
  • Server-side access could be used for further compromise, depending on process privileges
  • Availability may be affected through destructive or resource-intensive code execution
  • An attacker may execute arbitrary PHP code in the application process
  • Application secrets and configuration data could be exposed
  • Application data may be modified, deleted, or poisoned
  • Server-side access could be used for further compromise, depending on process privileges
  • Availability may be affected through destructive or resource-intensive code execution

General mitigation guidance

Mitigation generally focuses on maintaining a strict separation between template data and generated executable code.

Common defensive patterns include:

  • Using a maintained Smarty release that contains the relevant security correction
  • Preventing untrusted values from being interpreted as template control markers or generated PHP syntax
  • Applying strict context-aware validation and output encoding to assigned data
  • Restricting template cache directories from untrusted write access
  • Storing generated cache files outside user-controlled paths and applying least-privilege filesystem permissions
  • Running the PHP process with only the permissions required by the application
  • Disabling or isolating dynamic template features when they are not required

Mitigation generally focuses on maintaining a strict separation between template data and generated executable code.

Common defensive patterns include:

  • Using a maintained Smarty release that contains the relevant security correction
  • Preventing untrusted values from being interpreted as template control markers or generated PHP syntax
  • Applying strict context-aware validation and output encoding to assigned data
  • Restricting template cache directories from untrusted write access
  • Storing generated cache files outside user-controlled paths and applying least-privilege filesystem permissions
  • Running the PHP process with only the permissions required by the application
  • Disabling or isolating dynamic template features when they are not required

How teams detect issues like this

Organizations can look for this class of issue through:

  • Static analysis rules that identify user-controlled data entering template compilation or PHP code-generation paths
  • Code review checks for template markers, cache generation, and inheritance-state handling
  • Tests that render attacker-controlled values through inheritance and cache regeneration flows
  • Monitoring for unexpected modifications or newly generated PHP files in template cache directories
  • File-integrity policies and runtime controls that restrict executable code in cache locations
  • Automated security review tools that flag code-generation paths lacking context-aware validation

Organizations can look for this class of issue through:

  • Static analysis rules that identify user-controlled data entering template compilation or PHP code-generation paths
  • Code review checks for template markers, cache generation, and inheritance-state handling
  • Tests that render attacker-controlled values through inheritance and cache regeneration flows
  • Monitoring for unexpected modifications or newly generated PHP files in template cache directories
  • File-integrity policies and runtime controls that restrict executable code in cache locations
  • Automated security review tools that flag code-generation paths lacking context-aware validation

Sources

SourceLink
github.comgithub.com/smarty-php/smarty/commit/1cba51cb813563eb61d963c83d28cd59f26b858d
github.comgithub.com/smarty-php/smarty/commit/c0fdd4824aca4f67e814b50703cfee1dfde41414
github.comgithub.com/smarty-php/smarty/releases/tag/v4.5.8
github.comgithub.com/smarty-php/smarty/releases/tag/v5.8.5
github.comgithub.com/smarty-php/smarty/security/advisories/GHSA-3w63-v7pm-cq9x
vulncheck.comvulncheck.com/advisories/smarty-before-4.5.8-and-5-x-before-5.8.5-php-code-injection-via-extends-inheritance-cache

Frequently asked

questions

Potentially. Remote exploitation depends on whether a remote user can control assigned template data and cause the affected Smarty cache-generation and inclusion flow to run.

Not necessarily. The required access depends on the application's input paths; any unauthenticated or authenticated feature that passes attacker-controlled values into the vulnerable rendering path may be relevant.

Use a maintained Smarty release containing the security correction, prevent untrusted data from becoming executable template or PHP content, and restrict access to generated cache files.

Treat template data as untrusted, maintain clear boundaries between data and generated code, test inheritance and cache regeneration paths, and enforce least privilege for the PHP process and cache directories.

Potentially. Remote exploitation depends on whether a remote user can control assigned template data and cause the affected Smarty cache-generation and inclusion flow to run.

Not necessarily. The required access depends on the application's input paths; any unauthenticated or authenticated feature that passes attacker-controlled values into the vulnerable rendering path may be relevant.

Use a maintained Smarty release containing the security correction, prevent untrusted data from becoming executable template or PHP content, and restrict access to generated cache files.

Treat template data as untrusted, maintain clear boundaries between data and generated code, test inheritance and cache regeneration paths, and enforce least privilege for the PHP process and cache directories.

Find out what's already
exploitable in your codebase.