Skip to content

fix: read the Stripe secrets without the white space they were pasted with - #13

Merged
JasonYv merged 2 commits into
mainfrom
fix/trim-stripe-secrets
Nov 3, 2026
Merged

JasonYv merged 2 commits into
mainfrom
fix/trim-stripe-secrets

Conversation

@JasonYv

@JasonYv JasonYv commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Phase 2's last exit criterion: a purchase run end to end in Stripe's test mode, on the owner's sandbox, against a local site (npm run preview, events forwarded by stripe listen --latest). It found one defect, fixed here.

The defect

The webhook signing secret had been saved with the space before it on the line stripe listen prints. Mallok stores a plugin secret exactly as it is sent, so every delivery from Stripe was refused as signed with another secret (400), while the admin showed the secret as set. A shop in that state confirms no payment.

Neither Stripe secret can contain white space. Every reading of one now goes through stripeSecret in lib/stripe-secrets.ts, which trims it. That covers nine readings: checkout, the webhook route, the admin's order actions, the cron and the admin's checks. A test fails when any other file reads a secret directly.

Mallok's side is written up for the owner as M48: trim on save, and treat a value that is only white space as unset.

What the purchase covered

Each step was checked both in the shop's tables and through Stripe's API.

  • Paid.
    • The Checkout session matched the order: test mode, $275.00 USD, the line at its snapshot price, one shipping option named after the zone, card and Link only, adaptive pricing off.
    • The payment was delivered and answered 200.
    • Stock went from 3,000 to 2,950 with one ledger row, and the cart was emptied.
    • The same event delivered again took nothing.
  • Refunded from the admin. The refund was made at Stripe first, then the order was marked refunded and the stock put back.
  • Expired, two orders. Each was cancelled (expired) by Stripe's event, with the stock untouched.
  • Cancelled from the admin while unpaid. The session was closed at Stripe first, then the order cancelled (seller). Stripe's expiry event that followed changed nothing.
  • Follow-ups. A tick of Mallok's scheduled handler handed the buyer's three emails to Mallok, and none for the expiries.

The full account is in design §22.

Verification

  • npm run lint, npm run typecheck, npm test (1,104 tests in workerd and 54 project tests), npm run build and npm run smoke:shop all pass locally.
  • With the trim taken away, the three new tests go red.
  • With one raw reading of a secret put back, the one-place test goes red.

Docs

  • README, its translation and SECURITY.md no longer say the purchase has not been run, and list what is still untried at Stripe.
  • The README says how to recover an event stripe listen missed: its login lapses after an hour or two, after which it stops forwarding.
  • CLAUDE.md names the one place secrets are read.

Not verified

  • Not tried at Stripe:
    • Stripe Tax;
    • Apple Pay and Google Pay;
    • a card that asks for authentication;
    • an order in EUR or GBP;
    • an endpoint created in Stripe's dashboard.
  • Nothing was deployed and no email was delivered.

… with

The first purchase in Stripe's test mode found every webhook delivery
refused as signed with another secret: the signing secret had been saved
with the space before it on the line stripe listen prints, and Mallok keeps
a secret exactly as pasted. Neither secret can contain white space, so every
reading now goes through one function that trims it, and a test holds the
shop to that one place.
Phase 2's last exit criterion, run against a local site on the owner's
sandbox: paid, delivered twice, refunded, expired and cancelled. The README,
its translation and SECURITY.md no longer say it has not been run, and say
what is still untried at Stripe and how to recover an event stripe listen
missed.
@JasonYv
JasonYv merged commit 74a0e64 into main Nov 3, 2026
1 check passed
@JasonYv
JasonYv deleted the fix/trim-stripe-secrets branch November 3, 2026 12:16
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