From d8ddb83320524218c5d5f9c02eb21937385e1a5a Mon Sep 17 00:00:00 2001
From: Dominik Myszkowski
Date: Mon, 30 Nov 2026 15:22:08 +0100
Subject: [PATCH 1/4] feat(booking): optional redirect after a confirmed
booking (#268)
event_types.redirect_url and redirect_with_booking_id (migration 00077):
where the booker goes once a booking is confirmed, typically the operator's
thank-you page, optionally with ?booking_id= appended (off by default; the
booking id is a lookup key).
The value is an open-redirect surface, so it is checked three times:
validRedirectURL on save (absolute https, a host, no credentials, no
whitespace or control characters, <= 2000 chars), servedRedirectURL when a
page or the widget is given it (an invalid stored value is served as none
and logged), and BookingLogic.redirectTarget in the browser before use,
mirrored in embed.js.
- book.html: finalize() shows "Continue" and navigates after 1.5 s, leaving
time for the conversion push. Covers the Stripe return too: the success
URL now carries booking_id.
- embed.js: never navigates the host page; "Continue" opens the redirect in
a new tab (noopener).
- manage.html: no redirect; a reschedule or cancel is not a conversion.
- Admin: URL field and booking-id checkbox in the General tab (en/fr).
- New booker key "continue" in every locale.
Builds on the final confirmation state from the previous commit (#284).
---
CHANGELOG.md | 7 +
docs/ARCHITECTURE.md | 2 +
frontend/src/lib/api.ts | 6 +
frontend/src/lib/i18n/en.json | 3 +
frontend/src/lib/i18n/fr.json | 3 +
.../routes/event-types/[slug]/+page.svelte | 16 +
.../00077_event_type_redirect_url.sql | 19 ++
internal/handler/assets/booking-logic.js | 16 +
internal/handler/assets/booking-logic.test.js | 12 +
internal/handler/book.go | 101 ++++---
internal/handler/booking_final_state_test.go | 42 ++-
internal/handler/embed.js | 26 +-
internal/handler/event_type.go | 56 +++-
internal/handler/event_type_duplicate.go | 6 +-
internal/handler/event_type_duplicate_test.go | 1 +
internal/handler/redirect_url.go | 62 ++++
.../handler/redirect_url_internal_test.go | 275 ++++++++++++++++++
internal/handler/stripe_booking.go | 6 +-
internal/handler/templates/book.html | 26 +-
internal/handler/templates/booking.css | 4 +
internal/handler/testdata/book_final_state.js | 57 +++-
internal/i18n/locales/de-x-neutral.json | 1 +
internal/i18n/locales/de.json | 1 +
internal/i18n/locales/el.json | 1 +
internal/i18n/locales/en.json | 1 +
internal/i18n/locales/es.json | 1 +
internal/i18n/locales/fr-CA.json | 1 +
internal/i18n/locales/fr.json | 1 +
internal/i18n/locales/it.json | 1 +
internal/i18n/locales/nl.json | 1 +
internal/i18n/locales/pl.json | 1 +
internal/i18n/locales/pt.json | 1 +
internal/i18n/locales/sv.json | 1 +
33 files changed, 685 insertions(+), 73 deletions(-)
create mode 100644 internal/db/migrations/00077_event_type_redirect_url.sql
create mode 100644 internal/handler/redirect_url.go
create mode 100644 internal/handler/redirect_url_internal_test.go
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b6b81e11..57bcacfb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,13 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad
### Added
+- **Redirect after booking.** An event type can send the booker to a page of your own once
+ a booking is confirmed (Event type → General, `redirect_url`), typically a thank-you page
+ where site analytics count the conversion, optionally with `?booking_id=` appended. The
+ booking page shows a "Continue" button and moves on after a moment, also after paying
+ through Stripe. The embedded widget never leaves the host site: it offers "Continue" in a
+ new tab instead. Only absolute `https://` URLs without credentials are accepted, checked
+ when saved, when served and again in the browser. Migration `00077` adds the columns.
- **Delete a booking for an erasure request.** Owners and admins can now permanently remove a
booking from the Bookings list (trash icon, confirmation dialog; `DELETE /v1/bookings/{id}`).
It removes the booking with its attendees, answers, manage links and host assignments, plus the
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index bff405a7..6e8ef3db 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -415,6 +415,8 @@ The `phone_outbound` location type ("we'll call you") is the outbound counterpar
A confirmed booking is a **final state** on all three booking surfaces (#268). A page that kept its calendar live and re-enabled its submit button after confirming invited a second booking under a different email, which `max_active_bookings` cannot catch. On `book.html`, `finalize()` (on success, and on the return from Stripe Checkout) disables the calendar, month navigation, timezone and submit, resets the form, and every handler checks the `finalized` flag rather than relying on the markup alone; a `submitting` flag also drops a second submit while the first request is in flight. "Book another time" is a fresh load of the page without the Stripe return parameters, so no picked day, slot or host state survives. The embed widget renders its calendar disabled while `state.view === 'confirm'` and refuses a second submit; its "Book another time" resets the widget's own state and reloads the month, never navigating the host page. On `manage.html` the success views (rescheduled, cancelled) are final: `showView` no longer leaves them and neither action can be sent again, because the page's times describe the booking as it was; a reload shows it as it now is. `TestBookPage_confirmationIsFinal` runs book.html's real page script under node against a small fake DOM (`testdata/book_final_state.js`) to check that a second submit sends nothing; the widget and manage page are pinned at source level.
+An event type can set a **post-booking redirect** (`redirect_url`, `redirect_with_booking_id`, migration 00077, #268), typically the operator's own thank-you page, where site analytics count the conversion. Although admin-configured, it is an open-redirect surface, so it is checked three times: `validRedirectURL` when the event type is saved (absolute https, a host, no credentials: `https://trusted.example@evil.example/` reads as one site and goes to another; no whitespace or control characters; at most 2000 characters), `servedRedirectURL` when a page or the widget is given it (a stored value that no longer passes is served as no redirect and logged), and `redirectTarget` in the browser right before use (`booking-logic.js`, mirrored in `embed.js`). `redirect_with_booking_id` appends `?booking_id=`; it is off by default because the booking id is a lookup key (`GET /v1/bookings/{id}` is public). On `book.html`, `finalize()` shows a "Continue" button and navigates after a short delay (`REDIRECT_DELAY_MS`), which leaves time for the dataLayer/GA4 conversion pushed right after it; this covers the return from Stripe Checkout too, whose success URL carries `booking_id` for that purpose. The **embed widget never navigates the host page**: its confirmation offers "Continue", which opens the redirect in a new tab (`noopener`). The manage page does not redirect: a reschedule or a cancellation is not a conversion.
+
`internal/booking/service.go` (transactions) + `internal/handler/booking_handler.go`
(HTTP + async side effects).
diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts
index cd6c8723..a7a1e80a 100644
--- a/frontend/src/lib/api.ts
+++ b/frontend/src/lib/api.ts
@@ -39,6 +39,12 @@ export type EventType = {
* them. Off by default: the slots endpoint is public, so this makes the host's
* booked hours visible to anyone with the link. */
show_taken_slots: boolean;
+ /** Where the booking page sends the booker after a confirmed booking (absolute https,
+ * no credentials). Absent/null = no redirect. The embed widget only offers it as a
+ * "Continue" button that opens a new tab. */
+ redirect_url?: string | null;
+ /** Append ?booking_id= to redirect_url. */
+ redirect_with_booking_id: boolean;
/** Who sends the booker's calendar invite. 'calendar': each host's connected calendar,
* from the host's own address. 'calnode': Calnode's own invite, from the email sender
* in Settings → Email, so no host's personal address reaches the booker. 'none': no
diff --git a/frontend/src/lib/i18n/en.json b/frontend/src/lib/i18n/en.json
index 1a3870ce..baf41e95 100644
--- a/frontend/src/lib/i18n/en.json
+++ b/frontend/src/lib/i18n/en.json
@@ -1646,6 +1646,9 @@
"showTaken": "Show booked times as unavailable",
"showTakenHint": "Booked times appear struck through on the booking page instead of being hidden, so visitors can see the calendar filling up. Only times inside your working hours are shown, never the rest of your day.",
"showTakenWarning": "Anyone with the booking link can see which hours are taken.",
+ "redirectUrl": "Redirect after booking (optional)",
+ "redirectUrlHint": "After a confirmed booking, the booking page sends the booker here, for example your own thank-you page. Must start with https://. The embedded widget never leaves your site: it shows a Continue button that opens this page in a new tab.",
+ "redirectWithBookingId": "Add the booking ID to the address (?booking_id=…)",
"allowPhoneCall": "Let invitees choose a phone call by entering their number"
},
"location": {
diff --git a/frontend/src/lib/i18n/fr.json b/frontend/src/lib/i18n/fr.json
index b9af9802..8b620cd9 100644
--- a/frontend/src/lib/i18n/fr.json
+++ b/frontend/src/lib/i18n/fr.json
@@ -1646,6 +1646,9 @@
"showTaken": "Afficher les horaires réservés comme indisponibles",
"showTakenHint": "Les horaires réservés apparaissent barrés sur la page de réservation au lieu d'être masqués, afin que les visiteurs voient le calendrier se remplir. Seuls les horaires dans vos heures de travail sont affichés, jamais le reste de votre journée.",
"showTakenWarning": "Quiconque dispose du lien de réservation peut voir quels horaires sont pris.",
+ "redirectUrl": "Redirection après la réservation (facultatif)",
+ "redirectUrlHint": "Après une réservation confirmée, la page de réservation y envoie la personne, par exemple vers votre page de remerciement. Doit commencer par https://. Le widget intégré ne quitte jamais votre site : il affiche un bouton Continuer qui ouvre cette page dans un nouvel onglet.",
+ "redirectWithBookingId": "Ajouter l'identifiant de réservation à l'adresse (?booking_id=…)",
"allowPhoneCall": "Permettre aux invités de choisir un appel téléphonique en saisissant leur numéro"
},
"location": {
diff --git a/frontend/src/routes/event-types/[slug]/+page.svelte b/frontend/src/routes/event-types/[slug]/+page.svelte
index 84e6f5d4..fe2b78a2 100644
--- a/frontend/src/routes/event-types/[slug]/+page.svelte
+++ b/frontend/src/routes/event-types/[slug]/+page.svelte
@@ -88,6 +88,7 @@
display_order: 0,
name: '', slug: '', description: '', duration_minutes: 30, slot_interval_minutes: 30,
is_active: true, is_public: true, show_taken_slots: false,
+ redirect_url: '', redirect_with_booking_id: false,
invite_delivery: 'calendar' as EventType['invite_delivery'],
location_type: 'link', location_value: '',
buffer_before_minutes: 0, buffer_after_minutes: 0,
@@ -336,6 +337,8 @@
is_active: et.is_active,
is_public: et.is_public,
show_taken_slots: et.show_taken_slots ?? false,
+ redirect_url: et.redirect_url ?? '',
+ redirect_with_booking_id: et.redirect_with_booking_id ?? false,
invite_delivery: et.invite_delivery ?? 'calendar',
location_type: et.location_type,
location_value: et.location_value ?? '',
@@ -397,6 +400,9 @@
is_active: form.is_active,
is_public: form.is_public,
show_taken_slots: form.show_taken_slots,
+ // '' clears it server-side (null would mean "leave unchanged").
+ redirect_url: form.redirect_url.trim(),
+ redirect_with_booking_id: form.redirect_with_booking_id,
invite_delivery: form.invite_delivery,
allow_phone_call: allowPhoneCall,
location_type: form.location_type,
@@ -705,6 +711,16 @@
+
+
+
+
{$t('eventTypeEditor.general.redirectUrlHint')}
+
+
+
+
+
+
{#if isOnlineMeeting(form.location_type)}
{/if}
diff --git a/internal/db/migrations/00077_event_type_redirect_url.sql b/internal/db/migrations/00077_event_type_redirect_url.sql
new file mode 100644
index 00000000..0c77f47a
--- /dev/null
+++ b/internal/db/migrations/00077_event_type_redirect_url.sql
@@ -0,0 +1,19 @@
+-- +goose Up
+-- Where the booker goes after a confirmed booking: typically the operator's own thank-you
+-- page, which is also where site analytics usually count the conversion. Requested in
+-- discussion #268.
+--
+-- redirect_url is NULL when unset, and the booking page then shows its own final
+-- confirmation. It is admin-configured, but it is still an open-redirect surface, so it
+-- is validated when saved and again before the page navigates: an absolute https URL
+-- with a host and no credentials, nothing else.
+--
+-- redirect_with_booking_id appends ?booking_id= so the thank-you page can tie the
+-- conversion to the booking. Off by default: the booking id is a lookup key
+-- (GET /v1/bookings/{id} is public), so handing it to another site is the operator's call.
+ALTER TABLE event_types ADD COLUMN redirect_url TEXT;
+ALTER TABLE event_types ADD COLUMN redirect_with_booking_id INTEGER NOT NULL DEFAULT 0;
+
+-- +goose Down
+ALTER TABLE event_types DROP COLUMN redirect_with_booking_id;
+ALTER TABLE event_types DROP COLUMN redirect_url;
diff --git a/internal/handler/assets/booking-logic.js b/internal/handler/assets/booking-logic.js
index c2221521..ab85fc41 100644
--- a/internal/handler/assets/booking-logic.js
+++ b/internal/handler/assets/booking-logic.js
@@ -138,7 +138,23 @@
// consolidated onto it. If these are ever unified, the shared version must take the
// locale's list_separator/list_conjunction, not hardcode punctuation.
+ // redirectTarget is where to send the booker after a confirmed booking, or '' (#268):
+ // the event type's redirect_url, checked once more right before navigating even though
+ // the server already validated it on save and on serve, then ?booking_id= appended when
+ // the event type asks for it. Absolute https with a host and no credentials, exactly as
+ // the server's validRedirectURL; anything else yields '' and the page simply stays on
+ // its own confirmation. MIRRORED in embed.js (which does not load this module).
+ function redirectTarget(raw, bookingId, withId) {
+ if (typeof raw !== 'string' || raw === '' || /[\u0000-\u0020\u007f]/.test(raw)) return '';
+ var u;
+ try { u = new URL(raw); } catch (e) { return ''; }
+ if (u.protocol !== 'https:' || !u.hostname || u.username || u.password) return '';
+ if (withId && bookingId) u.searchParams.set('booking_id', String(bookingId));
+ return u.href;
+ }
+
return {
+ redirectTarget: redirectTarget,
dateKeyFromISO: dateKeyFromISO,
ymd: ymd,
groupSlotsByDay: groupSlotsByDay,
diff --git a/internal/handler/assets/booking-logic.test.js b/internal/handler/assets/booking-logic.test.js
index 39fadc62..79aa54ec 100644
--- a/internal/handler/assets/booking-logic.test.js
+++ b/internal/handler/assets/booking-logic.test.js
@@ -106,3 +106,15 @@ test('fmt leaves a string with no verbs untouched', () => {
assert.equal(B.fmt('No available times.', ['unused']), 'No available times.');
assert.equal(B.fmt('Inga lediga tider.'), 'Inga lediga tider.');
});
+
+test('redirectTarget: https only, no credentials, optional booking_id', () => {
+ assert.equal(B.redirectTarget('https://example.com/thanks', 'b1', false), 'https://example.com/thanks');
+ assert.equal(B.redirectTarget('https://example.com/thanks?src=cal', 'b 1', true),
+ 'https://example.com/thanks?src=cal&booking_id=b+1');
+ assert.equal(B.redirectTarget('https://example.com/thanks', '', true), 'https://example.com/thanks');
+ for (const bad of ['', 'http://example.com/', 'javascript:alert(1)', '//example.com/x', '/thanks',
+ 'https://user:pw@example.com/', 'https://trusted.example@evil.example/', 'https://exa mple.com/',
+ 'https://example.com/\nx', 'data:text/html,hi', null, undefined]) {
+ assert.equal(B.redirectTarget(bad, 'b1', true), '', String(bad));
+ }
+});
diff --git a/internal/handler/book.go b/internal/handler/book.go
index 7bddd295..56e35ba4 100644
--- a/internal/handler/book.go
+++ b/internal/handler/book.go
@@ -45,6 +45,11 @@ type bookQuestion struct {
type bookPageData struct {
PhoneChoice bool
+ // RedirectURL is where the page sends the booker once a booking is confirmed, or ""
+ // (#268). Re-validated here, not trusted from the row, and again in the browser.
+ // RedirectWithBookingID appends ?booking_id=.
+ RedirectURL string
+ RedirectWithBookingID bool
// PhoneRequired is the "we'll call you" location: the same phone field, but required,
// because the attendee's number is the only way the host can reach them.
PhoneRequired bool
@@ -353,16 +358,20 @@ func (h *Handler) PublicEventType(w http.ResponseWriter, r *http.Request) {
msgGreeting sql.NullString
allowPhoneCall bool
accentColor string
+ redirectRaw string
+ redirectWithID bool
)
err := h.db.QueryRowContext(r.Context(), `
SELECT et.id, et.name, COALESCE(et.description, ''),
et.duration_minutes, et.location_type, COALESCE(et.location_value, ''),
et.max_future_days, et.min_notice_minutes, et.routing_mode, u.name, COALESCE(u.avatar_url, ''),
- et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent
+ et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent,
+ COALESCE(et.redirect_url, ''), et.redirect_with_booking_id
FROM event_types et
JOIN users u ON u.id = et.user_id
WHERE et.slug = ? AND et.is_active = 1 AND et.is_public = 1`,
- slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, ¤cy, &msgGreeting, &allowPhoneCall, &accentColor)
+ slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, ¤cy, &msgGreeting, &allowPhoneCall, &accentColor,
+ &redirectRaw, &redirectWithID)
if errors.Is(err, sql.ErrNoRows) {
h.writeError(w, http.StatusNotFound, "event type not found")
return
@@ -373,6 +382,7 @@ func (h *Handler) PublicEventType(w http.ResponseWriter, r *http.Request) {
return
}
accentColor = accentOrDefault(accentColor)
+ redirectURL := h.servedRedirectURL(r, slug, redirectRaw)
hosts := h.displayHosts(r.Context(), etID, routingMode)
if len(hosts) == 0 {
@@ -442,12 +452,16 @@ func (h *Handler) PublicEventType(w http.ResponseWriter, r *http.Request) {
"assistant_greeting": assistantGreeting(msgGreeting, loc),
"price_cents": priceCents,
"currency": currency,
- "hosts": outHosts,
- "business_name": brand.BusinessName,
- "logo_url": abs(brand.LogoURL),
- "banner_url": abs(brand.BannerURL),
- "locale": loc.Code,
- "i18n": json.RawMessage(i18nJSON),
+ // Post-booking redirect (#268). The widget never navigates the host page with it:
+ // it offers a "Continue" that opens it in a new tab.
+ "redirect_url": redirectURL,
+ "redirect_with_booking_id": redirectWithID && redirectURL != "",
+ "hosts": outHosts,
+ "business_name": brand.BusinessName,
+ "logo_url": abs(brand.LogoURL),
+ "banner_url": abs(brand.BannerURL),
+ "locale": loc.Code,
+ "i18n": json.RawMessage(i18nJSON),
})
}
@@ -472,16 +486,20 @@ func (h *Handler) BookPage(w http.ResponseWriter, r *http.Request) {
msgGreeting sql.NullString
allowPhoneCall bool
accentColor string
+ redirectRaw string
+ redirectWithID bool
)
err := h.db.QueryRowContext(r.Context(), `
SELECT et.id, et.name, COALESCE(et.description, ''),
et.duration_minutes, et.location_type, COALESCE(et.location_value, ''),
et.max_future_days, et.min_notice_minutes, et.routing_mode, u.name, COALESCE(u.avatar_url, ''),
- et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent
+ et.price_cents, et.currency, et.msg_greeting, et.allow_phone_call, u.booking_accent,
+ COALESCE(et.redirect_url, ''), et.redirect_with_booking_id
FROM event_types et
JOIN users u ON u.id = et.user_id
WHERE et.slug = ? AND et.is_active = 1 AND et.is_public = 1`,
- slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, ¤cy, &msgGreeting, &allowPhoneCall, &accentColor)
+ slug).Scan(&etID, &name, &description, &durMins, &locType, &locValue, &maxDays, &minNotice, &routingMode, &hostName, &avatarURL, &priceCents, ¤cy, &msgGreeting, &allowPhoneCall, &accentColor,
+ &redirectRaw, &redirectWithID)
if errors.Is(err, sql.ErrNoRows) {
http.Error(w, "Page not found", http.StatusNotFound)
@@ -543,37 +561,40 @@ func (h *Handler) BookPage(w http.ResponseWriter, r *http.Request) {
loc := h.resolveLocaleWithFallback(r, brand.FallbackLocale)
i18nJSON, _ := loc.JSON()
+ redirectURL := h.servedRedirectURL(r, slug, redirectRaw)
data := bookPageData{
- PhoneChoice: allowPhoneCall && onlineMeetingLocation(locType),
- PhoneRequired: locType == phoneOutboundLocation,
- AccentColor: accentColor,
- AccentForeground: accentForeground(accentColor),
- Slug: slug,
- Name: name,
- Description: renderMarkdown(description),
- DurationLabel: durationLabel(durMins, loc),
- HostName: hosts[0].Name,
- HostInitial: hosts[0].Initial,
- AvatarURL: hosts[0].AvatarURL,
- Hosts: capHostFaces(hosts, maxHostFaces),
- HostsMore: hostsOverflow(hosts, maxHostFaces),
- HostsLabel: hostsLabel(hosts, loc),
- SoleHostName: soleHostName(hosts),
- MinNoticeLabel: noticeLabel(minNotice, loc),
- LocationLabel: locationLabel(locType, locValue, loc),
- PriceLabel: formatPrice(priceCents, currency),
- Locale: loc.Code,
- T: loc.T,
- I18NJSON: template.JS(i18nJSON), // #nosec G203 -- json.Marshal output, which escapes <,>,& by default; safe for embedding in a