Fix critical unauthenticated order tampering/IDOR in api/orders.php and reused named-param bug in admin order search

This commit is contained in:
2026-07-06 07:51:53 +00:00
parent 3c8e4d1dbc
commit f84a754370
2 changed files with 17 additions and 6 deletions
+4 -2
View File
@@ -45,8 +45,10 @@ if ($status) {
} }
if ($search) { if ($search) {
$where[] = '(order_number LIKE :search OR customer_name LIKE :search OR customer_email LIKE :search)'; $where[] = '(order_number LIKE :search1 OR customer_name LIKE :search2 OR customer_email LIKE :search3)';
$params['search'] = '%' . $search . '%'; $params['search1'] = '%' . $search . '%';
$params['search2'] = '%' . $search . '%';
$params['search3'] = '%' . $search . '%';
} }
if ($dateFrom) { if ($dateFrom) {
+13 -4
View File
@@ -23,15 +23,22 @@ switch ($method) {
"SELECT * FROM orders WHERE order_id = :id", "SELECT * FROM orders WHERE order_id = :id",
['id' => $orderId] ['id' => $orderId]
); );
if (!$order) { if (!$order) {
jsonResponse(['error' => 'Order not found'], 404); jsonResponse(['error' => 'Order not found'], 404);
} }
// Only the admin or the customer who placed this order may view it by raw id.
$customer = CustomerAuth::getUser();
$isOwner = $customer && (string)$customer['customer_id'] === (string)$order['customer_id'];
if (!AdminAuth::isLoggedIn() && !$isOwner) {
jsonResponse(['error' => 'Unauthorized'], 401);
}
$order['items'] = json_decode($order['items'], true); $order['items'] = json_decode($order['items'], true);
$order['shipping_address'] = json_decode($order['shipping_address'], true); $order['shipping_address'] = json_decode($order['shipping_address'], true);
unset($order['id']); unset($order['id']);
jsonResponse($order); jsonResponse($order);
} elseif ($orderNumber) { } elseif ($orderNumber) {
$email = $_GET['email'] ?? ''; $email = $_GET['email'] ?? '';
@@ -71,7 +78,9 @@ switch ($method) {
case 'POST': case 'POST':
// Update order status (admin) // Update order status (admin)
if ($action === 'update_status') { if ($action === 'update_status') {
// Admin check would go here if (!AdminAuth::isLoggedIn()) {
jsonResponse(['error' => 'Unauthorized'], 401);
}
$orderId = $input['order_id'] ?? ''; $orderId = $input['order_id'] ?? '';
$status = $input['status'] ?? ''; $status = $input['status'] ?? '';
$trackingNumber = $input['tracking_number'] ?? null; $trackingNumber = $input['tracking_number'] ?? null;