Repository navigation
fix: keep the order access token out of payments and stored emails readable by admins - #18
Merged
Merged
Conversation
…adable by admins
The ecommerce plugin hides an order's access token from the API and the admin
panel for everyone, but the site copied it into two places admins read: the
payment's redirectUrl and the stored order emails (emails and mail-outbox).
Payment return: the redirectUrl is now /shop/orders/return?t={returnToken},
billing's own return token. A route handler looks the payment up by it and
gives the browser a one-hour, httpOnly grant cookie for that one order (an
expiry plus an HMAC over the order number, no token inside), then redirects
to the plain order page. Checkout sets the same cookie for the browser that
placed the order.
Emails: order emails are rendered with a placeholder for the token, so the
emails document never holds it. The mailing plugin's beforeSend hook fills
the real token in on every send attempt, only when all recipients are the
order's customer, and fails the send when it cannot. The capturing transport
redacts the token before storing to mail-outbox; /mailbox restores the link
only for the member who placed the order.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0122PV8TJ7ELGdAX7H2hdrRU
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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.
Why
orders.accessToken(from@xtr-dev/payload-ecommerce0.3.0) opens an order page without signing in. The plugin hides the field from REST, GraphQL and the admin panel for everyone, admins included. The site still copied the full order link, token included, into two places an admin can read:payments.redirectUrl, the URL the shopper returns to after paying.emailscollection (html,textandvariables.orderToken) and the demo outbox (mail-outbox, shown on/mailbox).Workflow run snapshots were already stripped and are untouched.
What changed
Payment return
redirectUrlis now/shop/orders/return?t={returnToken}: billing's own per-payment return token, the mechanism bookings already use.src/app/(frontend)/shop/orders/return/route.ts, looks the payment up by that token on the server, sets an order grant cookie and redirects to the plain/shop/orders/<number>.src/lib/orderLinks.ts) is<expiry>.<HMAC-SHA256>over the order number, signed with the Payload secret. The cookie is httpOnly,SameSite=Lax, scoped to that order page's path, valid for one hour, andSecurewhen the site origin is https.placeOrderActionsets the same cookie for the browser that placed the order, so an order that costs nothing (or a payment page left without paying) still opens for a guest./checkout/returnforwards an order payment's token to the new route.Why a signed cookie and not the token. I weighed two ways to let the shopper in after the return:
/shop/orders/N?t=<accessToken>from the return routepayments.returnToken(admins can) could follow the return link and read the access token from the address bar. The token would also land in browser history and proxy logs on every checkout.Emails
sendOrderConfirmation/sendOrderShippedrender the template with a placeholder asorderToken, so the stored body, plain-text part and variables read…?t=sent-only-to-the-customer.beforeSendhook (withOrderLinkTokens) puts the real token in as the message is handed to the transport. It runs on every attempt, so a retried email gets a working link.to,ccorbccis not the order'scustomerEmail. Without the second check an admin could create anemailsdocument addressed to themselves, linked to someone's order, and have the token mailed to them.mail-outbox./mailboxrestores the working link only for the signed-in member who placed the order and received the message (getMailboxMessageinsrc/lib/mailbox.ts). Admins, and a member who merely shares an address with a guest order, see the placeholder. Guests cannot open the mailbox today (it needs an account), and that is unchanged.I chose send-time rendering over field-level read access or redacting after the send because it is the only option where the token is never written to the
emailscollection at all, and it keeps retries working without special cases.What an admin still sees
redirectUrlwith the payment'sreturnToken. Following it gives a one-hour grant for an order page the admin can already open as admin; it reveals no token.?t=sent-only-to-the-customer.Tests
tests/int/order-token.int.spec.ts(12 tests): grant signing and expiry, placeholder fill and redaction, the payment through Local API withoverrideAccess: false, REST and GraphQL, the guest and member return flows, stored versus sent email for the confirmation and shipped emails, the mailbox data per viewer, a retried failed send, an admin-crafted email, and a sweep of every collection an admin can read (Local API and REST) plus stored job payloads for any token of the orders placed in the file.tests/int/ecommerce.int.spec.tsupdated for the new return URL and stored link.tests/e2e/ecommerce.e2e.spec.ts: guest returns to the tokenless order page with the grant cookie, a stranger gets a 404, an admin finds only the return link and the placeholder over REST, the return link opens the order in another browser, the member opens the working link from their mailbox, and the admin sees the placeholder in the same message.Locally: lint, typecheck, 135 integration tests and the shop e2e spec (10 tests) pass. The e2e run was before the last two hardening changes (recipient check in
beforeSend, mailbox restore limited to the ordering member); CI covers those.Not covered here
customerEmailand trigger a new shipped email to that address. Closing that needs a rule about who may edit the address, which is a product decision.beforeSendreceiving the email with itsorderpopulated. Filed in the work tracker forpayload-mailing.🤖 Generated with Claude Code
https://claude.ai/code/session_0122PV8TJ7ELGdAX7H2hdrRU