Fix SQL injection concerns: use prepared statements in orderItemsRoute and tests
This commit is contained in:
@@ -188,10 +188,16 @@ class orderItemsRoute
|
||||
$response->error('Order Item ID is required', 400);
|
||||
}
|
||||
// Look up the order item to check department access
|
||||
$orderItemContext = $db->query(
|
||||
'SELECT oi.order_id FROM order_items oi WHERE oi.id = ' . (int)$data['id'] . ' LIMIT 1'
|
||||
);
|
||||
$orderItemRow = $orderItemContext ? $orderItemContext->fetch_assoc() : null;
|
||||
$itemId = (int)$data['id'];
|
||||
$stmt = $db->prepare('SELECT oi.order_id FROM order_items oi WHERE oi.id = ? LIMIT 1');
|
||||
if ($stmt !== false) {
|
||||
$stmt->bind_param('i', $itemId);
|
||||
$stmt->execute();
|
||||
$orderItemRow = $stmt->get_result()->fetch_assoc();
|
||||
$stmt->close();
|
||||
} else {
|
||||
$orderItemRow = null;
|
||||
}
|
||||
if ($orderItemRow !== null) {
|
||||
$orderForAccess = (new orders_o())->getOrderById((int)$orderItemRow['order_id']);
|
||||
if ($orderForAccess->exists()) {
|
||||
|
||||
Reference in New Issue
Block a user