Security and SSL

Critical vulnerability in PrestaShop 1.6.0.10 to 1.7.8.6 (Smarty MySQL cache)

Reviewed on 5 min read vulnerabilities security PrestaShop

On 22 July 2022 PrestaShop warned of a mass attack against shops from version 1.6.0.10 onwards. The attackers use an SQL injection (in the core or in a module) to enable the Smarty cache in MySQL and, through it, run code on the shop. With that they usually install a fake payment form that steals customers' cards.

  • PrestaShop 1.7.8.7 hardens the Smarty cache against this attack. Versions 8 and 9 already include it.
  • PrestaShop 1.6 received no fix: you need to apply the patch in this article.
  • The blockwishlist module (wishlist) from version 2.0.0 to 2.1.0 had one of the SQL injections used. Update it.

Definitive solution: update

Check your version in Advanced Parameters > Information. If it is a 1.7 earlier than 1.7.8.7, update. Ideally, move to a supported version: today the latest is 9.2.0, and the 8 branch is still receiving fixes (8.2.8). Also update all modules, especially third-party ones: the SQL injection usually comes from a module.

The guides error when updating with 1-Click Upgrade and connection error when updating PrestaShop cover the most common failures. Make a full backup (files and database) first.

Patch for shops that cannot update yet

If your shop is 1.6, or a 1.7 that you cannot update immediately, disable the Smarty cache in MySQL. Practically nobody uses it (the file cache is faster), so removing it does not affect how the shop works.

  1. Open the shop's config/smarty.config.inc.php file from the cPanel File Manager.
  2. Look for this block (it is around lines 40-43 in PrestaShop 1.6 and 43-46 in 1.7):
if (Configuration::get('PS_SMARTY_CACHING_TYPE') == 'mysql') {
    include _PS_CLASS_DIR_.'Smarty/SmartyCacheResourceMysql.php';
    $smarty->caching_type = 'mysql';
}
  1. Delete it entirely, all four lines, and save.
  2. Check that the shop loads normally.

Also, in Advanced Parameters > Performance, in the Smarty section, check that Caching type is set to File system and not MySQL.

This patch cuts off the code execution route, but does not fix the original SQL injection. You still need to update.

Apply it to many shops at once via SSH

If you manage several shops, first find the files that contain the block (change RUTA to the folder where the shops are, for example /home/usuario):

grep -rl --include=smarty.config.inc.php "PS_SMARTY_CACHING_TYPE') == 'mysql'" RUTA

And delete it in all of them (it removes the if line and the three following ones):

grep -rl --include=smarty.config.inc.php "PS_SMARTY_CACHING_TYPE') == 'mysql'" RUTA \
  | xargs sed -i "/PS_SMARTY_CACHING_TYPE') == 'mysql'/,+3d"

Then check that the files are still valid PHP:

find RUTA -name smarty.config.inc.php -exec php -l {} \;

Check whether the shop has already been attacked

Look for these signs:

  • A file called blm.php in the shop's main folder.
  • In the access logs: a POST request to a module, followed a second later by a visit to the home page and a request to /blm.php.
  • A card payment form you did not add on the checkout page, or customers reporting fraudulent charges.
  • Recently modified PHP files that do not match any update you made. Via SSH, find RUTA_TIENDA -name "*.php" -mtime -30 lists those changed in the last 30 days.

Not finding blm.php does not rule out an attack: attackers change the names. If you find any of these signs, put the shop into maintenance mode, make a backup of its current state and open a ticket: we will help you find the affected files. Deleting the Smarty block does not clean a shop that is already infected; once it is clean, change the passwords for the PrestaShop back office, the database and FTP.

You may also find useful

Something wrong or out of date? Tell us and we will review it.