Skip to content

Commit 782a934

Browse files
Fix multi-tenancy security vulnerability in OrdersController#show
The show action was not verifying that the order belongs to the current store, allowing users to view orders from other stores if they knew the order UUID. The fix ensures that: - Orders with a store_id must belong to the current_store_id - Orders without a store_id (unassigned drafts) are accessible - Orders from other stores return 404 Not Found Added integration test to prevent regression.
1 parent 61394da commit 782a934

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

apps/rails_application/app/controllers/orders_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ def index
44
end
55

66
def show
7-
@order_header = OrderHeader.find_by_uid(params[:id])
87
@order = Orders.find_order(params[:id])
98

10-
return not_found unless @order_header && @order
9+
return not_found unless @order
10+
return not_found if @order.store_id && @order.store_id != current_store_id
11+
12+
@order_header = OrderHeader.find_by_uid(params[:id])
1113
end
1214

1315
def new

apps/rails_application/test/integration/orders_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,24 @@ def test_cannot_edit_order_from_different_store
335335
assert_response(:not_found)
336336
end
337337

338+
def test_cannot_show_order_from_different_store
339+
store_id_a = SecureRandom.uuid
340+
store_id_b = SecureRandom.uuid
341+
342+
post "/admin/stores", params: { store_id: store_id_a, name: "Store A" }
343+
post "/admin/stores", params: { store_id: store_id_b, name: "Store B" }
344+
345+
post "/switch_store", params: { store_id: store_id_b }
346+
get "/orders/new"
347+
follow_redirect!
348+
order_id_in_store_b = retrieve_order_id_from_url
349+
350+
post "/switch_store", params: { store_id: store_id_a }
351+
get "/orders/#{order_id_in_store_b}"
352+
353+
assert_response(:not_found)
354+
end
355+
338356
private
339357

340358
def retrieve_order_id_from_url

0 commit comments

Comments
 (0)