mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-07-27 16:52:36 -05:00
Fix critical unauthenticated order tampering/IDOR in api/orders.php and reused named-param bug in admin order search
This commit is contained in:
+4
-2
@@ -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
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user