Strengthen SQL injection safeguards across objects and traits, add input validation and sanitization, and refine query efficiency with deduplication and null checks.
This commit is contained in:
@@ -1180,36 +1180,41 @@ class users_o extends db
|
||||
public function getCustomerNumbersWithAttributes(array $attributes): array
|
||||
{
|
||||
global $db;
|
||||
// Create an array to store the customer numbers
|
||||
$user_ids = [];
|
||||
$customer_numbers = [];
|
||||
// Loop through the attributes
|
||||
foreach ( $attributes as $attribute ) {
|
||||
// Get the customer numbers with the attribute
|
||||
$sql = "SELECT user_id FROM customer_attributes WHERE attribute = '$attribute'";
|
||||
$result = $db->query($sql);
|
||||
// Loop through the results
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
// Add the customer number to the array
|
||||
$user_ids[] = (int)$row['user_id'];
|
||||
$safeAttributes = [];
|
||||
foreach ($attributes as $attribute) {
|
||||
if (!is_scalar($attribute)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Remove duplicates from the array
|
||||
$user_ids = array_unique($user_ids);
|
||||
// Get the customer numbers from the user IDs
|
||||
foreach ( $user_ids as $user_id ) {
|
||||
// Get the customer number from the user ID
|
||||
$sql = "SELECT customer_number FROM $this->table WHERE id = $user_id";
|
||||
$result = $db->query($sql);
|
||||
// Loop through the results
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
// Add the customer number to the array
|
||||
$customer_numbers[] = (int)$row['customer_number'];
|
||||
$attribute = trim((string)$attribute);
|
||||
if ($attribute === '') {
|
||||
continue;
|
||||
}
|
||||
$safeAttributes[] = "'" . $db->escape_string($attribute) . "'";
|
||||
}
|
||||
// Remove duplicates from the array
|
||||
// Return the customer numbers
|
||||
return array_unique($customer_numbers);
|
||||
$safeAttributes = array_values(array_unique($safeAttributes));
|
||||
if (empty($safeAttributes)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$userIds = [];
|
||||
$sql = "SELECT DISTINCT user_id FROM customer_attributes WHERE attribute IN (" . implode(',', $safeAttributes) . ")";
|
||||
$result = $db->query($sql);
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$userIds[] = (int)$row['user_id'];
|
||||
}
|
||||
$userIds = array_values(array_unique($userIds));
|
||||
if (empty($userIds)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$customerNumbers = [];
|
||||
$sql = "SELECT customer_number FROM `$this->table` WHERE id IN (" . implode(',', array_map('intval', $userIds)) . ")";
|
||||
$result = $db->query($sql);
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$customerNumbers[] = (int)$row['customer_number'];
|
||||
}
|
||||
|
||||
return array_values(array_unique($customerNumbers));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1562,4 +1567,4 @@ class users_o extends db
|
||||
return "https://truckwash.io/auth/password-reset/" . $token;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user