fix: sanitize checkout site URL for Stripe redirects#329
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Motivation
success_url/cancel_urlwhenCOMMANDLAYER_SITE_URLis misconfigured (e.g. values containing commas or wrong protocol/host) that produced broken redirects.SITE_URL_INVALID) when the site URL is invalid so the caller receives a consistent error.Description
getSanitizedSiteUrl()toapi/admin/create-checkout-session.jsthat trims whitespace, removes a trailing slash, rejects values containing a comma, requireshttps:protocol, and enforces hostnamescommandlayer.orgorwww.commandlayer.org, defaulting tohttps://www.commandlayer.orgwhen missing.process.env.COMMANDLAYER_SITE_URLwith the sanitizedsiteUrlwhen building Stripesuccess_urlandcancel_urlinapi/admin/create-checkout-session.jsand return a 503 with statusSITE_URL_INVALIDand an explanatory error message when validation fails.tests/api-payments.test.jsto record the Stripe payload and to cover the sanitizer behavior with tests for defaulting, trimming, comma rejection,httprejection, unrelated domain rejection, and exactsuccess_url/cancel_urlconstruction.Testing
npm testand all tests passed (122 tests, 0 failures).cd examples/webhook-auto-verify && npm run checkand the checks succeeded.tests/api-payments.test.jspassed and validate the constructed Stripe URLs and rejection behavior.Codex Task