Our Stripe checkout returned 502 because the secret key was a PowerShell command
On November 17 we moved Ship & Shout billing from Lemon Squeezy to Stripe and turned on live mode. The next day, checkout failed with a bare “checkout failed” and a 502. The code was fine. The production secret key was not a key.
What we shipped
Stripe Checkout plus webhooks that write to a subscriptions table, three live prices (Pro monthly, Pro annual, Lifetime), and a live webhook endpoint. We tested the full flow in test mode first with a throwaway user, then deleted that user, then went live in one PR. Read-only scopes and no writes to the payment provider beyond creating Checkout sessions stayed as the rule.
The failure
The route caught the Stripe error and returned a generic 502, so the user saw “checkout failed” and we saw nothing useful. The first change (PR #153) was boring and necessary: log the Stripe error type, code, param and message, never the key or request body. The next failing request printed a StripeAuthenticationError: Invalid API Key provided.
The cause
Vercel masks sensitive env values in the CLI, so we couldn’t just read the value back. The error plus the stored value’s shape gave it away: STRIPE_SECRET_KEY in Production contained the text of a PowerShell command, not a key. We had piped the secret from the clipboard, and the clipboard held the command at that moment, so that is what got stored. Separately, the webhook secret was stored as an empty value.
What we changed
- Trim and validate env at the edge. An earlier fix already trimmed whitespace from the key and webhook secret; the error path now logs enough to tell “bad key” from “Stripe is down” at a glance.
- Check the clipboard before storing a secret. Confirm it starts with
sk_live_(or the expected prefix) before piping it intovercel env add. Never trust that the clipboard holds what you think. - Log on the failure path first. Hobby plan runtime logs last about an hour, so an error you don’t log at the moment it happens is gone before you look.
- Redeploy after changing env. Env changes only apply to new builds. We re-rolled the key in Stripe, set it again, and redeployed.
Takeaway
A 502 from a payment route isn’t a payments bug until the error says so. Make the failure path loud before launch, and verify secrets by their shape rather than by the fact that the command exited zero. Checkout has worked since the key was replaced.
Ship & Shout turns your week of commits (and revenue, if you want) into an honest post you approve before it goes anywhere. Try it on any public repo, no account needed. Also on the blog: how the whole thing runs on a $0 stack.
