Skip to content

fix(shop): v4.5.1 — require proof of access to view or pay an order by number - #220

Merged
thunpisit merged 2 commits into
mainfrom
fix/order-page-access
Oct 25, 2026
Merged

thunpisit merged 2 commits into
mainfrom
fix/order-page-access

Conversation

@thunpisit

Copy link
Copy Markdown
Contributor

Security fix

/[locale]/order/[orderNumber] looked the order up by number alone whenever ?email= was absent. Order numbers are sequential, so an anonymous visitor could enumerate every customer's name, email, phone and shipping address. Any signed-in account (customers included) could too. The return-request action and pay-by-orderNumber had the same gap; the latter let a stranger re-point someone's pending order at a new charge.

Fix

src/lib/server/shop/order-access.ts: canViewOrder() allows only

  • staff (admin+)
  • the owning account (user id, or a verified email equal to the order's)
  • the order's email (?email= from receipts, /lookup)
  • the browser that placed the order (checkout/start sets an HMAC-signed khaopad_order_access cookie, SameSite=Lax so it survives the payment provider's redirect back)

Refusals render the same 404 as a missing order. Applied to the order page load, the requestReturn action, and checkout/pay when called by number. orderId (unguessable nanoid) is unchanged. The order page's retry button now sends the order email it already holds.

Ported from codustry/bactrack-website 70d37f5 (already live there).

Verification

  • pnpm lint 0 errors · pnpm check 0 errors · 1129/1129 tests (1114 + 15 new) · build OK · contract-guard OK · css-inventory +0
  • wrangler dev with local D1, seeded order:
request result
anonymous, number only 404
missing order 404 (identical page apart from the echoed URL)
wrong ?email= 404
right ?email= (any case) 200
forged access cookie 404
real checkout → order page, same browser 200
same order, another browser 404
pay by number: placing browser / right email reaches provider (503 not configured locally)
pay by number: anyone else 404

Rollout note

Existing guests lose cookie-less access to past order pages; receipt links carry ?email= and keep working.

🤖 Generated with Claude Code

thunpisit and others added 2 commits October 25, 2026 14:23
The customer order page looked orders up by number alone whenever no
?email= was given, and order numbers are sequential — so anyone could
walk KHP-2026-00001, 00002, … and read every buyer's name, email,
phone and shipping address. Any signed-in account, customers included,
could do the same. The return-request action and pay-by-orderNumber
had the same gap.

Access now needs one of: staff (admin+), the owning account (user id,
or a verified email matching the order), the order's email (receipt
links and /lookup), or the browser that placed the order — checkout/
start sets an HMAC-signed cookie (keyed by BETTER_AUTH_SECRET) so a
guest returning from the payment page still lands on their order.
Refusals are the same 404 as a missing order.

Ported from bactrack-website 70d37f5, with a generic cookie name and a
verified-email requirement on the account-email path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thunpisit
thunpisit merged commit 107c797 into main Oct 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant