diff --git a/bot/commands.ts b/bot/commands.ts index 0a184a17..f2f54eba 100644 --- a/bot/commands.ts +++ b/bot/commands.ts @@ -668,6 +668,11 @@ const addInvoicePHI = async ( // only orders with status PAID_HOLD_INVOICE are released payments if (order.status !== 'PAID_HOLD_INVOICE') return; + // Only the order's buyer may (re)submit the payout invoice. The order id + // comes from the callback data, so we verify the caller is the buyer + // before entering the invoice flow. + if (!ctx.user || String(order.buyer_id) !== String(ctx.user._id)) return; + const buyer = await User.findOne({ _id: order.buyer_id }); if (buyer === null) return; if (order.amount === 0) { diff --git a/bot/start.ts b/bot/start.ts index f9b4a27a..e083e62c 100644 --- a/bot/start.ts +++ b/bot/start.ts @@ -895,6 +895,11 @@ const initialize = ( const order = await Order.findOne({ _id: ctx.match[1] }); if (!order) return; + // Only the order's buyer may set/replace the payout invoice. The order + // id comes from the callback data, so we verify the caller is the buyer + // before driving the invoice flow. + if (String(order.buyer_id) !== String(ctx.user._id)) return; + if (order.status === 'WAITING_BUYER_INVOICE') { await addInvoice(ctx, bot, order); } else {