blockwishlist is a prestashop extension which adds a block containing the customer’s wishlists. In affected versions an authenticated customer can perform SQL injection. This issue is fixed in version 2.1.1. Users are advised to upgrade. There are no known workarounds for this issue.

Summary

  • CVE ID: CVE-2022-31101
  • Published at: 2022-06-24
  • Advisory source: PrestaShop
  • Platform: PrestaShop
  • Product: blockwishlist
  • Impacted release: >= 2.0.0 and <= 2.1.1
  • Product author: PrestaShop
  • Weakness: CWE-89
  • Severity: high (8.8)

Description

An authenticated customer can perform SQL injection.

CVSS base metrics

  • Attack vector: network
  • Attack complexity: low
  • Privilege required: low
  • User interaction: none
  • Scope: unchanged
  • Confidentiality: high
  • Integrity: high
  • Availability: high

Vector string: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Possible malicious usage

Technical and personal data leaks Obtain admin access Remove all data of the linked PrestaShop

Proof of concept

Based on this POC

curl -v 'http://website.com/module/blockwishlist/view?id_wishlist=1&order=product.name%2C%20%28select%20case%20when%20%28id_customer%3D1%29%20then%20%28SELECT%20SLEEP%287%29%29%20else%201%20end%20from%20ps_customer%20where%20id_customer%3D1%29%3B%20--.asc'

Patch of release 2.1.0 to 2.1.1

Issue is fixed in 2.1.1 in this patch

--- a/src/Search/WishListProductSearchProvider.php
+++ b/src/Search/WishListProductSearchProvider.php
@@ -35,6 +35,7 @@ use PrestaShop\PrestaShop\Core\Product\Search\SortOrderFactory;
 use Product;
 use Shop;
 use Symfony\Component\Translation\TranslatorInterface;
+use Validate;
 use WishList;
 
 /**
@@ -167,7 +168,10 @@ class WishListProductSearchProvider implements ProductSearchProviderInterface
 
         if ('products' === $type) {
             $sortOrder = $query->getSortOrder()->toLegacyOrderBy(true);
-            $querySearch->orderBy($sortOrder . ' ' . $query->getSortOrder()->toLegacyOrderWay());
+            $sortWay = $query->getSortOrder()->toLegacyOrderWay();
+            if (Validate::isOrderBy($sortOrder) && Validate::isOrderWay($sortWay)) {
+                $querySearch->orderBy($sortOrder . ' ' . $sortWay);
+            }
             $querySearch->limit((int) $query->getResultsPerPage(), ((int) $query->getPage() - 1) * (int) $query->getResultsPerPage());
             $products = $this->db->executeS($querySearch);

Other recommendations

  • It’s recommended to upgrade to the latest version of the module blockwishlist up to 2.1.1.

Please note, blockwishlist is often forked to be customized.

  • To help improve the security of your PrestaShop installation, we recommend upgrading to the latest version. One of the benefits of upgrading is that it will disable the use of multiquery executions (separated by semicolons). However, please be aware that this will not protect your shop against SQL injection attacks that use the UNION clause to steal data. Additionally, it’s important to note that PrestaShop includes a function called pSQL, which includes a strip_tags function. This helps protect your shop against Stored XSS (also known as XSS T2) of Category 1. If a pSQL function is missing, it could potentially expose your project to critical Stored XSS vulnerabilities due to edge cases. Therefore, it’s crucial to ensure that all relevant functions are properly implemented and used consistently throughout your project.
  • Change the default database prefix ps_ by a new longer arbitrary prefix. Nevertheless, be warned that this is useless against blackhats with DBA senior skill because of a design vulnerability in DBMS
  • Activate OWASP 942’s rules on your WAF (Web application firewall), be warned that you will probably break your backoffice and you will need to pre-configure some bypasses against these set of rules.