Fix IDOR on client /orders/view/{order} routes#14
Open
LaAlexita wants to merge 2 commits into
Open
Conversation
The Client\OrdersController accepted route-bound Order models on
view/payments/emails/members/subscription/subscribe without checking
that the authenticated user is the order owner (or an accepted active
member). Any logged-in customer could change the {order:id} segment in
the URL and read another customer's package, status, due date,
payments, invited members, subscription metadata, and provider
transaction IDs.
Add a private authorizeOrderAccess() helper that aborts 403 unless
the user is the order owner or an active OrderMember (status=active
with user_id matching the current user, which is how invites are
linked once accepted in OrderActions::acceptInviteAsClient).
Call it at the top of every method that renders order-bound content.
There was a problem hiding this comment.
Pull request overview
This PR addresses an IDOR vulnerability in the client-facing order routes by ensuring the authenticated user is authorized to access a route-bound Order (either as the order owner or an active order member) before rendering order-related pages or creating a subscription.
Changes:
- Added a controller-level
authorizeOrderAccess(Order $order)authorization helper. - Invoked the authorization helper at the start of all order-bound client actions (
view,payments,emails,members,subscription,subscribe).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+74
to
+86
| private function authorizeOrderAccess(Order $order): void | ||
| { | ||
| if ($order->user_id === auth()->id()) { | ||
| return; | ||
| } | ||
|
|
||
| $isActiveMember = $order->members() | ||
| ->where('status', 'active') | ||
| ->where('user_id', auth()->id()) | ||
| ->exists(); | ||
|
|
||
| abort_unless($isActiveMember, 403); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.Suggestion cannot be applied right now. Please check back later.
Summary
The
Client\OrdersControllerwas accepting route-boundOrdermodels onview,payments,emails,members,subscription, andsubscribewithout checking that the authenticated user actually owns the order (or is an accepted member of it). Any logged-in customer could change the{order:id}segment in the URL and read another customer's order data.Concretely, an authenticated attacker could browse:
/orders/view/<foreign_order_id>— package, billing cycle, status, due date, last renewal/orders/view/<foreign_order_id>/payments— paid payment descriptions, amounts, gateways, transaction IDs, dates/orders/view/<foreign_order_id>/emails— email subjects, from/to, status (the email body link is gated, but the metadata isn't)/orders/view/<foreign_order_id>/members— invited member emails and status/orders/view/<foreign_order_id>/subscription— subscription IDs, gateways, billing dates/orders/view/<foreign_order_id>/subscription/subscribe/<gateway_id>— creates aSubscriptionrow pointing at someone else's orderCWE-639 (Authorization Bypass Through User-Controlled Key) / CWE-200.
Fix
Add a private
authorizeOrderAccess(Order $order)helper toClient\OrdersControllerand call it at the top of every method that renders order-bound content. The helper aborts with 403 unless one of:$order->user_id === auth()->id()— the requester owns the order, orOrderMemberrow for this order withstatus = 'active'anduser_id = auth()->id()— the requester accepted an invitation.Condition (2) mirrors how
OrderActions::acceptInviteAsClient()activates a member (sets bothstatus='active'anduser_id), so accepted members keep their existing access.Test plan
Reproduced against a running install with two accounts (
OWNERowns order#2,ATTACKERhas no relation to it).Before the fix, with
ATTACKER's session cookie:After the fix (same cookie, same order):
Owner access (
OWNER's cookie on order#2) and accepted-member access continue to work — the helper short-circuits on theuser_idmatch or the active-member query.