Skip to content

Rewrite localhost redirect targets to the run public origin - #61

Merged
midagedev merged 1 commit into
mainfrom
feature/run-scoped-redirect-rewrite
Jun 10, 2026
Merged

Rewrite localhost redirect targets to the run public origin#61
midagedev merged 1 commit into
mainfrom
feature/run-scoped-redirect-rewrite

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Summary

Follow-up to #60. Run-scoped public bases fixed checkout/portal entry URLs, but caller-provided redirect targets (success_url, portal return_url) still come from globally shared config (e.g. STRIPE_SUCCESS_URL = https://localhost:8080/checkout-success in 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 is https://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 base https://localhost:18689 → link/redirect https://localhost:18689/checkout-success

The rewrite happens only at display/redirect time — stored data and Stripe-shaped fields stay untouched:

  • GET /v1/checkout/sessions/{id} keeps success_url exactly as created and adds the rewritten link as the extension field billtap_return_url; the completion response carries the same key beside the untouched session object (webhook payloads and evidence are unaffected).
  • The hosted checkout page prefers billtap_return_url for its "Return to app" link (one-line frontend change).
  • Portal session responses keep return_url as provided; only the hosted url query embeds the rewritten target, which drives both the "Return to business" link and the post-action redirect.
  • External domains (e.g. accounts.dev-dentbird.com) are never rewritten; runs without a configured base keep redirects byte-for-byte unchanged.

Verification

  • go test ./... passes; existing tests unchanged
  • New API tests: origin rewrite with path/query preserved (no base-path appended), original success_url in retrieve/complete responses, portal return_url field original with rewritten URL query, 127.0.0.1 + scheme swap, external host skipped, unconfigured handler (global env only) fully untouched
  • New server test: /runs/run-a (configured) gets billtap_return_url, /runs/run-b (unconfigured) does not
  • npm run typecheck and npm run build pass

🤖 Generated with Claude Code

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>
@midagedev
midagedev merged commit 90672e8 into main Jun 10, 2026
1 of 3 checks passed
@midagedev
midagedev deleted the feature/run-scoped-redirect-rewrite branch June 10, 2026 22:13
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