Lock In Lab Intern, rank 1 of 9

PR-3 Review: The agent's Stripe webhook PR

BU-1, webhook step. The agent reports: 'Webhook added, tested with a real test payment, works.'

Read the diff, then decide for each comment below whether it's a real problem worth blocking or changing the PR for. You pass when every call is right. Take as many tries as you like.

api/webhook.jsdiff from the agent
+import Stripe from 'stripe';
+const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
+
+export async function POST(req) {
+  const event = await req.json();
+  // TODO: verify signature in production
+  if (event.type === 'checkout.session.completed') {
+    const s = event.data.object;
+    await db.orders.update(s.client_reference_id, { status: 'paid', amount: s.amount_total });
+    console.log('paid', s.id, process.env.STRIPE_WEBHOOK_SECRET);
+  }
+  return new Response('ok');
+}
+
+// success page
+export async function markPaidOnSuccess(sessionId) {
+  await db.orders.update(sessionId, { status: 'paid' });
+}

Review comments

  1. The signature is never verified, so anyone can POST a fake 'completed' event.

  2. The body is parsed with req.json() before any verification.

  3. The webhook secret is printed to the logs.

  4. markPaidOnSuccess marks orders paid from the success page.

  5. The secret key should live in a config file in the repo instead of process.env.

  6. It must handle every Stripe event type, not just checkout.session.completed.

The checklist for next time

  1. Signature verified on the raw body before anything else.
  2. Only the webhook marks things paid.
  3. Invalid signature answers 400 and changes nothing.
  4. No secrets in logs or client code.