Rewrite localhost redirect targets to the run public origin - #61
Merged
Conversation
Callers often store one static redirect URL (success_url, portal return_url) in shared config while each CI job's stack listens on its own port, so hosted-page return links pointed at a dead port even after run-scoped public bases fixed the session URLs themselves. When a run has a configured public_base_url, hosted pages now repoint localhost/127.0.0.1 redirect targets at that run's origin, keeping path and query. The rewrite happens only at display/redirect time: checkout retrieve and completion responses keep success_url exactly as stored and expose the rewritten link through the billtap_return_url extension field (preferred by the hosted checkout page), and portal responses keep return_url as provided while the hosted portal URL query carries the rewritten target. External domains and runs without a configured base are untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Summary
Follow-up to #60. Run-scoped public bases fixed checkout/portal entry URLs, but caller-provided redirect targets (
success_url, portalreturn_url) still come from globally shared config (e.g.STRIPE_SUCCESS_URL = https://localhost:8080/checkout-successin a shared Mongo SystemVariable), so the hosted checkout "Return to app" link and portal return redirect pointed at a dead port in multi-job CI (ERR_CONNECTION_REFUSED, observed in run 27304138834: link →https://localhost:8080/...while the job origin ishttps://localhost:18689).When a run has a configured
public_base_url, hosted pages now repoint localhost/127.0.0.1 redirect targets at that run's origin (scheme+host+port swapped, path/query preserved):success_url=https://localhost:8080/checkout-success+ run basehttps://localhost:18689→ link/redirecthttps://localhost:18689/checkout-successThe rewrite happens only at display/redirect time — stored data and Stripe-shaped fields stay untouched:
GET /v1/checkout/sessions/{id}keepssuccess_urlexactly as created and adds the rewritten link as the extension fieldbilltap_return_url; the completion response carries the same key beside the untouched session object (webhook payloads and evidence are unaffected).billtap_return_urlfor its "Return to app" link (one-line frontend change).return_urlas provided; only the hostedurlquery embeds the rewritten target, which drives both the "Return to business" link and the post-action redirect.accounts.dev-dentbird.com) are never rewritten; runs without a configured base keep redirects byte-for-byte unchanged.Verification
go test ./...passes; existing tests unchangedsuccess_urlin retrieve/complete responses, portalreturn_urlfield original with rewritten URL query,127.0.0.1+ scheme swap, external host skipped, unconfigured handler (global env only) fully untouched/runs/run-a(configured) getsbilltap_return_url,/runs/run-b(unconfigured) does notnpm run typecheckandnpm run buildpass🤖 Generated with Claude Code