Skip to content

Commit f05189c

Browse files
grunchclaude
andauthored
fix: verify buyer ownership before entering the setinvoice flow (#833)
The addInvoicePHI handler and the setinvoice_ action looked up the order by the id carried in the callback data and then entered the invoice flow without checking that the caller is the order's buyer. Add an explicit check that ctx.user is the buyer in both entry points, so only the buyer can set or replace the payout invoice of their order. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5d0cae2 commit f05189c

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

bot/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ const addInvoicePHI = async (
668668
// only orders with status PAID_HOLD_INVOICE are released payments
669669
if (order.status !== 'PAID_HOLD_INVOICE') return;
670670

671+
// Only the order's buyer may (re)submit the payout invoice. The order id
672+
// comes from the callback data, so we verify the caller is the buyer
673+
// before entering the invoice flow.
674+
if (!ctx.user || String(order.buyer_id) !== String(ctx.user._id)) return;
675+
671676
const buyer = await User.findOne({ _id: order.buyer_id });
672677
if (buyer === null) return;
673678
if (order.amount === 0) {

bot/start.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,11 @@ const initialize = (
895895
const order = await Order.findOne({ _id: ctx.match[1] });
896896
if (!order) return;
897897

898+
// Only the order's buyer may set/replace the payout invoice. The order
899+
// id comes from the callback data, so we verify the caller is the buyer
900+
// before driving the invoice flow.
901+
if (String(order.buyer_id) !== String(ctx.user._id)) return;
902+
898903
if (order.status === 'WAITING_BUYER_INVOICE') {
899904
await addInvoice(ctx, bot, order);
900905
} else {

0 commit comments

Comments
 (0)