CVE-2023-6981 (published 2024-01-03T06:15Z)

The WP SMS – Messaging & SMS Notification for WordPress, WooCommerce, GravityForms, etc plugin for WordPress is vulnerable to SQL Injection via the 'group_id' parameter in all versions up to, and including, 6.5 due to insufficient escaping on the user supplied parameter and lack of sufficient preparation on the existing SQL query.  This makes it possible for authenticated attackers, with contributor-level access and above, to append additional SQL queries into already existing queries that can be used to extract sensitive information from the database. This can leveraged to achieve Reflected Cross-site Scripting.

CVSS v3 base score: 4.9, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:N/A:N)

Weakness information:
cwe_id: CWE-89
cwe_name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
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.
extended_description: 
            
            
         
         

Fix information:
repo_url: https://github.com/wp-sms/wp-sms
commit_details: repo_url: https://github.com/wp-sms/wp-sms
author: unknown
author_date: 2023-12-23 16:23:12+04:00
msg: Fix XSS vulnerability in subscribers page
repository: repo_url: https://github.com/wp-sms/wp-sms
repo_name: wp-sms/wp-sms
description: The Best WordPress SMS Messaging and Notification Plugin for WordPress!
repo_language: PHP
owner: wp-sms
file_changes: filename: class-wpsms-subscribers-table.php
change_type: ModificationType.MODIFY
diff: @@ -168,12 +168,13 @@ class Subscribers_List_Table extends \WP_List_Table
     public function process_bulk_action()
     {
         $current_action = $this->current_action();
-        //Detect when a bulk action is being triggered...
+        // Detect when a bulk action is being triggered
+
         // Search action
         if (isset($_GET['s']) and $_GET['s']) {
             $metaValue   = Helper::prepareMobileNumberQuery($this->db->esc_like($_GET['s']));
             $metaValue   = "'" . implode("','", $metaValue) . "'";
-            $prepare     = $this->db->prepare("SELECT * from `{$this->tb_prefix}sms_subscribes` WHERE name LIKE %s OR mobile IN ({$metaValue})", '%' . $this->db->esc_like($_GET['s']) . '%');
+            $prepare     = $this->db->prepare("SELECT * FROM `{$this->tb_prefix}sms_subscribes` WHERE name LIKE %s OR mobile IN ({$metaValue})", '%' . $this->db->esc_like($_GET['s']) . '%');
             $this->data  = $this->get_data($prepare);
             $this->count = $this->get_total($prepare);
         }
@@ -312,12 +313,13 @@ class Subscribers_List_Table extends \WP_List_Table
         return ($order === 'asc') ? $result : -$result; //Send final sort direction to usort
     }
 
-    //set $per_page item as int number
+    // Set $per_page item as int number
     public function get_data($query = '')
     {
         $page_number = ($this->get_pagenum() - 1) * $this->limit;
         $orderby     = "ORDER BY {$this->tb_prefix}sms_subscribes.date DESC";
         $where       = "";
+        $params      = array();
 
         if (isset($_REQUEST['orderby'])) {
             $orderby = "ORDER BY {$this->tb_prefix}sms_subscribes.{$_REQUEST['orderby']} {$_REQUEST['order']}";
@@ -326,29 +328,35 @@ class Subscribers_List_Table extends \WP_List_Table
         if (!$query) {
             if (isset($_GET['group_id']) && $_GET['group_id']) {
                 $group_id = sanitize_text_field($_GET['group_id']);
-                $where    = "WHERE group_ID = {$group_id}";
+                $where    = "WHERE group_ID = %d";
+                $params[] = intval($group_id);
             }
 
             if (isset($_GET['country_code']) && $_GET['country_code']) {
                 $country_code = sanitize_text_field($_GET['country_code']);
 
                 if ($where) {
-                    $where .= " AND mobile LIKE '{$country_code}%'";
+                    $where .= " AND mobile LIKE %s";
                 } else {
-                    $where = "WHERE mobile LIKE '{$country_code}%'";
+                    $where = "WHERE mobile LIKE %s";
                 }
+
+                $params[] = $country_code . '%';
             }
-            $query = $this->db->prepare("SELECT * FROM {$this->tb_prefix}sms_subscribes {$where} {$orderby} LIMIT %d OFFSET %d", $this->limit, $page_number);
+
+            $params[] = $this->limit;
+            $params[] = $page_number;
+
+            $query = $this->db->prepare("SELECT * FROM {$this->tb_prefix}sms_subscribes {$where} {$orderby} LIMIT %d OFFSET %d", $params);
         } else {
             $query .= $this->db->prepare(" LIMIT %d OFFSET %d", $this->limit, $page_number);
         }
 
         $result = $this->db->get_results($query, ARRAY_A);
-
         return $result;
     }
 
-    //get total items on different Queries
+    // Get total items on different Queries
     public function get_total($query = '')
     {
         if (!$query) {

programming_language: PHP