CVE-2023-28843: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') (CWE-89)
value: PrestaShop/paypal is an open source module for the PrestaShop web commerce ecosystem which provides paypal payment support. A SQL injection vulnerability found in the PrestaShop paypal module from release from 3.12.0 to and including 3.16.3 allow a remote attacker to gain privileges, modify data, and potentially affect system availability. The cause of this issue is that SQL queries were being constructed with user input which had not been properly filtered. Only deployments on PrestaShop 1.6 are affected. Users are advised to upgrade to module version 3.16.4. There are no known workarounds for this vulnerability.
CWE description: The product constructs all or part of an SQL command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended SQL command when it is sent to a downstream component. Without sufficient removal or quoting of SQL syntax in user-controllable inputs, the generated SQL query can cause those inputs to be interpreted as SQL instead of ordinary user data.
CVSS v3 base score: 9.8
Published: 2023-03-31T18:15Z
Repository: https://github.com/202ecommerce/paypal
Language: PHP
Files changed: ipn.php, paypal.php
Commit date: 2022-10-10 15:36:11 +0200
Commit message: refs #36741

Diff: diff --git a/ipn.php b/ipn.php
index 45525e9..e780823 100644
--- a/ipn.php
+++ b/ipn.php
@@ -253,7 +253,7 @@ if (Tools::getValue('receiver_email') == Configuration::get('PAYPAL_BUSINESS_ACC
             unlink($custom['id_cart'].'.txt');
         }
     }
 } elseif (Tools::isSubmit('custom') && (int)Configuration::get('PAYPAL_PAYMENT_METHOD') == HSS) {
     $custom = Tools::jsonDecode(Tools::getValue('custom'), true);
-    Db::getInstance()->insert('paypal_hss_email_error', array('id_cart' => $custom['id_cart'], 'email' => Tools::getValue('receiver_email')));
+    Db::getInstance()->insert('paypal_hss_email_error', array('id_cart' => (int) $custom['id_cart'], 'email' => pSQL(Tools::getValue('receiver_email', ''))));
 }
diff --git a/paypal.php b/paypal.php
index dd05918..1a2e4a9 100644
--- a/paypal.php
+++ b/paypal.php
@@ -1924,11 +1924,11 @@ class PayPal extends PaymentModule
                 } else {
                     $refresh_webprofile = false;
                 }
 
                 $new_hss_email = Tools::getValue('api_business_account');
-                Db::getInstance()->delete('paypal_hss_email_error', 'email = "'.$new_hss_email.'"');
+                Db::getInstance()->delete('paypal_hss_email_error', 'email = "'. pSQL($new_hss_email) .'"');
 
                 Configuration::updateValue('PAYPAL_BUSINESS', (int) Tools::getValue('business'));
                 Configuration::updateValue('PAYPAL_PAYMENT_METHOD', (int) Tools::getValue('paypal_payment_method'));
                 $expressCheckout->setApiUser(trim(Tools::getValue('api_username')));
                 $expressCheckout->setApiPassword(trim(Tools::getValue('api_password')));

Vulnerable code:     Db::getInstance()->insert('paypal_hss_email_error', array('id_cart' => $custom['id_cart'], 'email' => Tools::getValue('receiver_email')));
                Db::getInstance()->delete('paypal_hss_email_error', 'email = "'.$new_hss_email.'"');
Fixed code:     Db::getInstance()->insert('paypal_hss_email_error', array('id_cart' => (int) $custom['id_cart'], 'email' => pSQL(Tools::getValue('receiver_email', ''))));
                Db::getInstance()->delete('paypal_hss_email_error', 'email = "'. pSQL($new_hss_email) .'"');