Fix security issue in order status endpoint #10573
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Issue
ensure_order_tokeninOrderStatusController(permalink) checks iforder_tokenis truthy instead of checking if it'spresent?.Outcome
Passing an empty string
''as the token allows to query any complete order without knowing it's token.Description
Searching for complete orders forms a pipeline where the last step should filter out every order whose token doesn't match the token provided by the client:
spree/core/app/finders/spree/orders/find_complete.rb
Lines 12 to 18 in 4cc2c29
by_tokenfirst checks whether token is present:spree/core/app/finders/spree/orders/find_complete.rb
Lines 34 to 36 in 4cc2c29
spree/core/app/finders/spree/orders/find_complete.rb
Lines 50 to 54 in 4cc2c29
This completely skips filtering by token when the token is blank. In particular, it skips it when the token is an empty string
''. Since empty string evaluates totrue,ensure_order_tokenwould accept it as valid input. This makes it possible to query for any complete order without knowing it's token.Steps to reproduce
<order_number>.X-Spree-Order-Tokenheader to an empty string''./api/v2/storefront/order_status/<order_number>.You should now see the order's details.