Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Remove legacy Pulse Account checkout bootstrap

rcourtman87bec03f58b1
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index 60dfb9bf7f..33405b57a3 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -539,20 +539,21 @@ hosted-only accounts do not render self-hosted license, refund, privacy, or
self-hosted escalation paths by default, and self-hosted-only accounts do not
front-load an empty hosted-billing block before the real self-hosted jobs.
That same runtime handoff contract now also covers product-originated
-self-hosted upgrade arrivals: `/portal?service=upgrade&checkout_intent_id=...`
+self-hosted upgrade arrivals: `/portal?portal_handoff_id=...`
may open a portal-owned upgrade job inside `Billing`, but it must not
fabricate broader self-hosted commercial history or reveal
retrieve/refund/privacy panels for a hosted-only account that only arrived
through an upgrade CTA.
That same commercial contract now also includes the self-hosted purchase
return path. Product-originated upgrade handoffs must include a canonical
-commercial-owned `checkout_intent_id`. Pulse still binds checkout completion
-to a signed `purchase_return_token`, but that token must stay inside the
-Pulse-owned activation callback path rather than leaking into the portal
-arrival URL. The portal runtime must resolve the verified checkout intent
-through the shared commercial API and use only that opaque intent when it
-starts checkout instead of trusting browser referrer state or loose `feature`
-/ `return_url` parameters. Pulse's public `GET /auth/license-purchase-activate`
+commercial-owned `portal_handoff_id` that resolves server-side to the bound
+checkout intent. Pulse still binds checkout completion to a signed
+`purchase_return_token`, but that token must stay inside the Pulse-owned
+activation callback path rather than leaking into the portal arrival URL. The
+portal runtime must resolve the verified portal handoff through the shared
+commercial API and use only that owned handoff-derived checkout intent when it
+starts checkout instead of trusting browser referrer state, raw
+`checkout_intent_id`, or loose `feature` / `return_url` parameters. Pulse's public `GET /auth/license-purchase-activate`
callback then serves an auto-submitting bridge into the owned POST activation
path, which redeems the completed checkout through the shared
license/commercial API before returning the browser to the owned billing plan
diff --git a/docs/release-control/v6/internal/subsystems/cloud-paid.md b/docs/release-control/v6/internal/subsystems/cloud-paid.md
index c2ed9b18db..012df98903 100644
--- a/docs/release-control/v6/internal/subsystems/cloud-paid.md
+++ b/docs/release-control/v6/internal/subsystems/cloud-paid.md
@@ -468,13 +468,16 @@ public pricing surface inside the runtime, and the authenticated portal shell
must not collapse back into a public-site-only waystation for new-purchase
depth. That handoff now starts through Pulse-owned `GET /auth/license-purchase-start`,
which mints a signed `purchase_return_token`, creates a commercial-owned
-`checkout_intent_id` that already contains the resolved Pulse success/cancel
-targets, and sends only that opaque `checkout_intent_id` to `Pulse Account`
-before the browser leaves for the portal. `Pulse Account` must resolve that
-checkout intent through the shared commercial API before it starts checkout,
-so the portal never trusts browser referrer state, loose `feature` /
-`return_url` query parameters, or a Pulse-local handoff URL for self-hosted
-purchase completion. Stripe success now lands on Pulse's public
+`portal_handoff_id` that resolves to the bound checkout intent plus Pulse
+success/cancel targets, and sends only that opaque `portal_handoff_id` to
+`Pulse Account` before the browser leaves for the portal. `Pulse Account`
+must resolve that server-owned handoff through the shared commercial API
+before it starts checkout, so the portal never trusts browser referrer state,
+loose `feature` / `return_url` query parameters, or a raw browser-supplied
+`checkout_intent_id` for self-hosted purchase completion. The portal proxy
+must expose `GET /v1/checkout/portal-handoff` as the canonical browser
+bootstrap and must not keep the retired `GET /v1/checkout/intent` bootstrap
+path alive once `portal_handoff_id` is the owned contract. Stripe success now lands on Pulse's public
`frontend-modern/src/utils/pricingHandoff.ts` and
`frontend-modern/src/pages/PricingHandoff.tsx` may only hand operators into
Pulse-owned `GET /auth/license-purchase-start`; they must not construct
diff --git a/internal/cloudcp/portal/commercial_proxy.go b/internal/cloudcp/portal/commercial_proxy.go
index 010ab2abbe..d5dd280a73 100644
--- a/internal/cloudcp/portal/commercial_proxy.go
+++ b/internal/cloudcp/portal/commercial_proxy.go
@@ -20,9 +20,8 @@ var allowedCommercialProxyEndpoints = map[string]map[string]struct{}{
http.MethodGet: {},
http.MethodPost: {},
},
- "/v1/checkout/intent": {
- http.MethodGet: {},
- http.MethodPost: {},
+ "/v1/checkout/portal-handoff": {
+ http.MethodGet: {},
},
"/v1/manage/request": {
http.MethodPost: {},
diff --git a/internal/cloudcp/portal/dist/portal_app.js b/internal/cloudcp/portal/dist/portal_app.js
index 6ba669ff30..3df4d9f369 100644
--- a/internal/cloudcp/portal/dist/portal_app.js
+++ b/internal/cloudcp/portal/dist/portal_app.js
@@ -831,6 +831,8 @@
return {
openBillingPanelID: "",
upgradeFeatureKey: "",
+ upgradePortalHandoffID: "",
+ upgradePortalHandoff: createQueryState(null),
upgradeCheckoutIntentID: "",
upgradeCheckoutIntent: createQueryState(null),
upgradePricing: createQueryState(null),
@@ -1410,7 +1412,8 @@
if (plans.length === 0) {
return "";
}
- var checkoutDisabled = billingState.upgradeCheckout.pending || billingState.upgradeCheckoutIntent.status === "loading" || !String(billingState.upgradeCheckoutIntentID || "").trim() || billingState.upgradeCheckoutIntent.status !== "ready";
+ var portalHandoffID = String(billingState.upgradePortalHandoffID || "").trim();
+ var checkoutDisabled = billingState.upgradeCheckout.pending || !portalHandoffID || billingState.upgradeCheckoutIntent.status === "loading" || !String(billingState.upgradeCheckoutIntentID || "").trim() || billingState.upgradeCheckoutIntent.status !== "ready";
return '<div class="billing-upgrade-plan-grid">' + plans.map(function(plan) {
var buttons = Array.isArray(plan.buttons) ? plan.buttons : [];
var checkoutButtons = buttons.filter(function(button) {
@@ -1427,6 +1430,7 @@
var root = getElement3("upgrade-billing-root");
if (!root) return;
var featureKey = String(billingState.upgradeFeatureKey || "").trim();
+ var portalHandoffID = String(billingState.upgradePortalHandoffID || "").trim();
var pricingState = billingState.upgradePricing;
var checkoutIntentState = billingState.upgradeCheckoutIntent;
var checkoutIntentID = String(billingState.upgradeCheckoutIntentID || "").trim();
@@ -1438,15 +1442,15 @@
if (billingState.upgradeCheckout.error) {
summaryItems.push('<div class="billing-status visible error">' + escapeText(billingState.upgradeCheckout.error) + "</div>");
}
- if (!checkoutIntentID) {
+ if (!portalHandoffID) {
summaryItems.push(
- '<div class="billing-status visible error">Open this upgrade from Pulse Pro billing so Pulse Account can verify the secure checkout intent before checkout.</div>'
+ '<div class="billing-status visible error">Open this upgrade from Pulse Pro billing so Pulse Account can verify the secure upgrade handoff before checkout.</div>'
);
} else if (checkoutIntentState.status === "loading") {
- summaryItems.push('<div class="billing-status visible">Verifying the secure Pulse Pro checkout intent...</div>');
+ summaryItems.push('<div class="billing-status visible">Verifying the secure Pulse Pro upgrade handoff...</div>');
} else if (checkoutIntentState.status === "error") {
- summaryItems.push('<div class="billing-status visible error">' + escapeText(checkoutIntentState.error || "Failed to verify the secure Pulse Pro checkout intent.") + "</div>");
- } else if (checkoutIntentState.status === "ready") {
+ summaryItems.push('<div class="billing-status visible error">' + escapeText(checkoutIntentState.error || "Failed to verify the secure Pulse Pro upgrade handoff.") + "</div>");
+ } else if (checkoutIntentState.status === "ready" && checkoutIntentID) {
summaryItems.push('<div class="billing-status visible success">Pulse Account will return completed checkout directly to Pulse Pro billing.</div>');
}
if (pricingState.status === "loading" && !pricingState.data) {
@@ -1679,6 +1683,8 @@
var nextState = createPortalBillingState();
billingState.openBillingPanelID = nextState.openBillingPanelID;
billingState.upgradeFeatureKey = nextState.upgradeFeatureKey;
+ billingState.upgradePortalHandoffID = nextState.upgradePortalHandoffID;
+ billingState.upgradePortalHandoff = nextState.upgradePortalHandoff;
billingState.upgradeCheckoutIntentID = nextState.upgradeCheckoutIntentID;
billingState.upgradeCheckoutIntent = nextState.upgradeCheckoutIntent;
billingState.upgradePricing = nextState.upgradePricing;
@@ -1772,46 +1778,62 @@
}
async function resolveUpgradeCheckoutIntent(force) {
var billingState = getBillingState();
- var checkoutIntentID = String(billingState.upgradeCheckoutIntentID || "").trim();
- if (!checkoutIntentID) return;
+ var portalHandoffID = String(billingState.upgradePortalHandoffID || "").trim();
+ if (!portalHandoffID) return;
if (!force && (billingState.upgradeCheckoutIntent.status === "loading" || billingState.upgradeCheckoutIntent.status === "ready")) {
return;
}
updateBillingState(function(nextBillingState) {
+ beginQueryState(nextBillingState.upgradePortalHandoff, null);
beginQueryState(nextBillingState.upgradeCheckoutIntent, null);
});
try {
- var result = await api.getCommercialJSON(
- "/v1/checkout/intent?checkout_intent_id=" + encodeURIComponent(checkoutIntentID)
+ var resolvedCheckoutIntentID = "";
+ var resolvedFeature = "";
+ var handoff = await api.getCommercialJSON(
+ "/v1/checkout/portal-handoff?portal_handoff_id=" + encodeURIComponent(portalHandoffID)
);
- var resolvedCheckoutIntentID = String(result.checkout_intent_id || "").trim();
+ resolvedCheckoutIntentID = String(handoff.checkout_intent_id || "").trim();
+ resolvedFeature = String(handoff.feature || "").trim();
+ updateBillingState(function(nextBillingState) {
+ resolveQueryState(nextBillingState.upgradePortalHandoff, handoff);
+ }, false);
if (!resolvedCheckoutIntentID) {
- throw new Error("Pulse Account could not verify the secure Pulse Pro checkout intent.");
+ throw new Error("Pulse Account could not verify the secure Pulse Pro upgrade handoff.");
}
- var resolvedFeature = String(result.feature || "").trim();
updateBillingState(function(nextBillingState) {
- resolveQueryState(nextBillingState.upgradeCheckoutIntent, result);
+ resolveQueryState(nextBillingState.upgradeCheckoutIntent, {
+ checkout_intent_id: resolvedCheckoutIntentID,
+ feature: resolvedFeature
+ });
nextBillingState.upgradeCheckoutIntentID = resolvedCheckoutIntentID;
nextBillingState.upgradeFeatureKey = resolvedFeature;
});
} catch (err) {
updateBillingState(function(nextBillingState) {
+ nextBillingState.upgradeCheckoutIntentID = "";
+ failQueryState(
+ nextBillingState.upgradePortalHandoff,
+ null,
+ err instanceof Error ? err.message : "Failed to verify the secure Pulse Pro upgrade handoff."
+ );
failQueryState(
nextBillingState.upgradeCheckoutIntent,
null,
- err instanceof Error ? err.message : "Failed to verify the secure Pulse Pro checkout intent."
+ err instanceof Error ? err.message : "Failed to verify the secure Pulse Pro upgrade handoff."
);
});
}
}
async function startUpgradeCheckout(planKey, tier, billingCycle) {
if (!planKey || !tier || !billingCycle) return;
+ var portalHandoffID = String(getBillingState().upgradePortalHandoffID || "").trim();
var checkoutIntentID = String(getBillingState().upgradeCheckoutIntentID || "").trim();
- if (!checkoutIntentID) {
+ if (!portalHandoffID || !checkoutIntentID) {
updateBillingState(function(nextBillingState) {
failMutationState(
nextBillingState.upgradeCheckout,
- "Pulse Account could not verify the secure checkout intent. Reopen the upgrade flow from Pulse Pro billing."
+ "Pulse Account could not verify the secure upgrade handoff. Reopen the upgrade flow from Pulse Pro billing."
);
});
return;
@@ -2122,7 +2144,7 @@
}
function renderBillingRuntime() {
var billingState = getBillingState();
- if (billingState.openBillingPanelID === "upgrade-billing-panel" || !!billingState.upgradeFeatureKey || !!billingState.upgradeCheckoutIntentID) {
+ if (billingState.openBillingPanelID === "upgrade-billing-panel" || !!billingState.upgradeFeatureKey || !!billingState.upgradePortalHandoffID) {
void loadUpgradePricing(false);
void resolveUpgradeCheckoutIntent(false);
}
@@ -2608,7 +2630,7 @@
var accounts = Array.isArray(context.bootstrap.accounts) ? context.bootstrap.accounts : [];
var hosted = hasHostedAccounts(accounts);
var showSelfHostedCommercial = hasSelfHostedCommercial(context.bootstrap);
- var showSelfHostedUpgradeHandoff = context.billingState.openBillingPanelID === "upgrade-billing-panel" || !!normalizeUpgradeFeatureKey(context.billingState.upgradeFeatureKey) || !!String(context.billingState.upgradeCheckoutIntentID || "").trim();
+ var showSelfHostedUpgradeHandoff = context.billingState.openBillingPanelID === "upgrade-billing-panel" || !!normalizeUpgradeFeatureKey(context.billingState.upgradeFeatureKey) || !!String(context.billingState.upgradePortalHandoffID || "").trim();
var showSelfHostedBillingShell = showSelfHostedCommercial || showSelfHostedUpgradeHandoff;
var shellSections = visibleShellSections(context.bootstrap);
var preferredSection = context.activeSection || preferredPortalShellSection(context.bootstrap);
@@ -2903,7 +2925,7 @@
function normalizeHandoffEmail(value) {
return String(value || "").trim();
}
- function normalizeUpgradeCheckoutIntentID(value) {
+ function normalizeUpgradePortalHandoffID(value) {
var trimmed = String(value || "").trim();
if (!trimmed) return "";
return /^[A-Za-z0-9_-]+$/.test(trimmed) ? trimmed : "";
@@ -2930,17 +2952,22 @@
function readPortalRuntimeHandoff(locationHref = window.location.href) {
try {
var params = new URL(locationHref).searchParams;
+ var upgradePortalHandoffID = normalizeUpgradePortalHandoffID(params.get("portal_handoff_id"));
+ var openBillingPanelID = normalizeHandoffBillingPanel(params.get("service"));
+ if (!openBillingPanelID && upgradePortalHandoffID) {
+ openBillingPanelID = "upgrade-billing-panel";
+ }
return {
email: normalizeHandoffEmail(params.get("email")),
- openBillingPanelID: normalizeHandoffBillingPanel(params.get("service")),
- upgradeCheckoutIntentID: normalizeUpgradeCheckoutIntentID(params.get("checkout_intent_id")),
+ openBillingPanelID,
+ upgradePortalHandoffID,
upgradeFeatureKey: normalizeUpgradeFeatureKey2(params.get("feature"))
};
} catch {
return {
email: "",
openBillingPanelID: "",
- upgradeCheckoutIntentID: "",
+ upgradePortalHandoffID: "",
upgradeFeatureKey: ""
};
}
@@ -2980,13 +3007,13 @@
store.setActiveShellSection("billing");
store.updateBillingState(function(billingState) {
billingState.openBillingPanelID = handoff.openBillingPanelID;
- billingState.upgradeCheckoutIntentID = handoff.upgradeCheckoutIntentID;
+ billingState.upgradePortalHandoffID = handoff.upgradePortalHandoffID;
billingState.upgradeFeatureKey = handoff.upgradeFeatureKey;
}, { notify: false });
- } else if (handoff.upgradeFeatureKey || handoff.upgradeCheckoutIntentID) {
+ } else if (handoff.upgradeFeatureKey || handoff.upgradePortalHandoffID) {
store.setActiveShellSection("billing");
store.updateBillingState(function(billingState) {
- billingState.upgradeCheckoutIntentID = handoff.upgradeCheckoutIntentID;
+ billingState.upgradePortalHandoffID = handoff.upgradePortalHandoffID;
billingState.upgradeFeatureKey = handoff.upgradeFeatureKey;
}, { notify: false });
}
diff --git a/internal/cloudcp/portal/frontend/dev.mjs b/internal/cloudcp/portal/frontend/dev.mjs
index 20d1ec5530..45a1b9905c 100644
--- a/internal/cloudcp/portal/frontend/dev.mjs
+++ b/internal/cloudcp/portal/frontend/dev.mjs
@@ -537,6 +537,20 @@ function routeCommercialAPI(request, response, url, scenario) {
return;
}
+ if (request.method === 'GET' && route === '/v1/checkout/portal-handoff') {
+ const portalHandoffID = String(url.searchParams.get('portal_handoff_id') || '').trim();
+ if (portalHandoffID !== 'cph_preview_upgrade') {
+ sendJSON(response, 400, { error: 'portal_handoff_id is invalid' });
+ return;
+ }
+ sendJSON(response, 200, {
+ portal_handoff_id: portalHandoffID,
+ checkout_intent_id: 'cki_preview_upgrade',
+ feature: 'max_monitored_systems',
+ });
+ return;
+ }
+
if (request.method === 'GET' && route === '/v1/checkout/session') {
sendJSON(response, 200, {
status: 'fulfilled',
@@ -612,6 +626,10 @@ function routeCommercialAPI(request, response, url, scenario) {
if (route === '/v1/checkout/session') {
readJSONBody(request).then(function(body) {
+ if (String(body.checkout_intent_id || '').trim() !== 'cki_preview_upgrade') {
+ sendJSON(response, 400, { error: 'Pulse Account could not verify the secure Pulse Pro upgrade handoff.' });
+ return;
+ }
const successURL = String(body.success_url || '').replace('{CHECKOUT_SESSION_ID}', 'cs_preview_success');
sendJSON(response, 200, {
url: successURL || successRedirect,
diff --git a/internal/cloudcp/portal/frontend/src/app.test.ts b/internal/cloudcp/portal/frontend/src/app.test.ts
index b4318ca4d8..ebe7e1a053 100644
--- a/internal/cloudcp/portal/frontend/src/app.test.ts
+++ b/internal/cloudcp/portal/frontend/src/app.test.ts
@@ -151,7 +151,6 @@ describe('portal app', function() {
openBillingPanelID: 'retrieve-billing-panel',
upgradePortalHandoffID: '',
- upgradeCheckoutIntentID: '',
upgradeFeatureKey: '',
}
);
diff --git a/internal/cloudcp/portal/frontend/src/billing.ts b/internal/cloudcp/portal/frontend/src/billing.ts
index 6a094b9efa..9bde9f5774 100644
--- a/internal/cloudcp/portal/frontend/src/billing.ts
+++ b/internal/cloudcp/portal/frontend/src/billing.ts
@@ -41,7 +41,6 @@ import type {
PortalBillingFlowID,
PortalBillingState,
PortalCheckoutSessionCreateResponse,
- PortalUpgradeCheckoutIntentModel,
PortalUpgradePortalHandoffModel,
PortalUpgradePricingModel,
VerificationFlowState,
@@ -196,39 +195,25 @@ export function installBillingRuntime(deps: BillingRuntimeDeps): void {
async function resolveUpgradeCheckoutIntent(force: boolean) {
var billingState = getBillingState();
var portalHandoffID = String(billingState.upgradePortalHandoffID || '').trim();
- var checkoutIntentID = String(billingState.upgradeCheckoutIntentID || '').trim();
- if (!portalHandoffID && !checkoutIntentID) return;
+ if (!portalHandoffID) return;
if (!force && (billingState.upgradeCheckoutIntent.status === 'loading' || billingState.upgradeCheckoutIntent.status === 'ready')) {
return;
}
updateBillingState(function(nextBillingState) {
- if (portalHandoffID) {
- beginQueryState(nextBillingState.upgradePortalHandoff, null);
- }
+ beginQueryState(nextBillingState.upgradePortalHandoff, null);
beginQueryState(nextBillingState.upgradeCheckoutIntent, null);
});
try {
- var resolvedCheckoutIntentID = checkoutIntentID;
+ var resolvedCheckoutIntentID = '';
var resolvedFeature = '';
- if (portalHandoffID) {
- var handoff = await api.getCommercialJSON<PortalUpgradePortalHandoffModel>(
- '/v1/checkout/portal-handoff?portal_handoff_id=' + encodeURIComponent(portalHandoffID),
- );
- resolvedCheckoutIntentID = String(handoff.checkout_intent_id || '').trim();
- resolvedFeature = String(handoff.feature || '').trim();
- updateBillingState(function(nextBillingState) {
- resolveQueryState(nextBillingState.upgradePortalHandoff, handoff);
- }, false);
- } else {
- var legacyResult = await api.getCommercialJSON<PortalUpgradeCheckoutIntentModel>(
- '/v1/checkout/intent?checkout_intent_id=' + encodeURIComponent(checkoutIntentID),
- );
- resolvedCheckoutIntentID = String(legacyResult.checkout_intent_id || '').trim();
- resolvedFeature = String(legacyResult.feature || '').trim();
- updateBillingState(function(nextBillingState) {
- resolveQueryState(nextBillingState.upgradeCheckoutIntent, legacyResult);
- }, false);
- }
+ var handoff = await api.getCommercialJSON<PortalUpgradePortalHandoffModel>(
+ '/v1/checkout/portal-handoff?portal_handoff_id=' + encodeURIComponent(portalHandoffID),
+ );
+ resolvedCheckoutIntentID = String(handoff.checkout_intent_id || '').trim();
+ resolvedFeature = String(handoff.feature || '').trim();
+ updateBillingState(function(nextBillingState) {
+ resolveQueryState(nextBillingState.upgradePortalHandoff, handoff);
+ }, false);
if (!resolvedCheckoutIntentID) {
throw new Error('Pulse Account could not verify the secure Pulse Pro upgrade handoff.');
}
@@ -242,13 +227,12 @@ export function installBillingRuntime(deps: BillingRuntimeDeps): void {
});
} catch (err) {
updateBillingState(function(nextBillingState) {
- if (portalHandoffID) {
- failQueryState(
- nextBillingState.upgradePortalHandoff,
- null,
- err instanceof Error ? err.message : 'Failed to verify the secure Pulse Pro upgrade handoff.',
- );
- }
+ nextBillingState.upgradeCheckoutIntentID = '';
+ failQueryState(
+ nextBillingState.upgradePortalHandoff,
+ null,
+ err instanceof Error ? err.message : 'Failed to verify the secure Pulse Pro upgrade handoff.',
+ );
failQueryState(
nextBillingState.upgradeCheckoutIntent,
null,
@@ -260,8 +244,9 @@ export function installBillingRuntime(deps: BillingRuntimeDeps): void {
async function startUpgradeCheckout(planKey: string, tier: string, billingCycle: string) {
if (!planKey || !tier || !billingCycle) return;
+ var portalHandoffID = String(getBillingState().upgradePortalHandoffID || '').trim();
var checkoutIntentID = String(getBillingState().upgradeCheckoutIntentID || '').trim();
- if (!checkoutIntentID) {
+ if (!portalHandoffID || !checkoutIntentID) {
updateBillingState(function(nextBillingState) {
failMutationState(
nextBillingState.upgradeCheckout,
@@ -585,8 +570,7 @@ export function installBillingRuntime(deps: BillingRuntimeDeps): void {
if (
billingState.openBillingPanelID === 'upgrade-billing-panel' ||
!!billingState.upgradeFeatureKey ||
- !!billingState.upgradePortalHandoffID ||
- !!billingState.upgradeCheckoutIntentID
+ !!billingState.upgradePortalHandoffID
) {
void loadUpgradePricing(false);
void resolveUpgradeCheckoutIntent(false);
diff --git a/internal/cloudcp/portal/frontend/src/billing_view.test.ts b/internal/cloudcp/portal/frontend/src/billing_view.test.ts
index 7be025d683..e79c88b243 100644
--- a/internal/cloudcp/portal/frontend/src/billing_view.test.ts
+++ b/internal/cloudcp/portal/frontend/src/billing_view.test.ts
@@ -317,4 +317,50 @@ describe('services view', function() {
(document.querySelector('[data-account-billing-action="upgrade-start-checkout"]') as HTMLButtonElement).disabled,
).toBe(true);
});
+
+ it('blocks legacy checkout-intent arrivals without a verified portal handoff', function() {
+ document.body.innerHTML = '<div id="upgrade-billing-root"></div>';
+
+ var billingState = createPortalBillingState();
+ billingState.upgradeCheckoutIntentID = 'cki_legacy';
+ billingState.upgradeCheckoutIntent.status = 'ready';
+ billingState.upgradeCheckoutIntent.data = {
+ checkout_intent_id: 'cki_legacy',
+ feature: 'max_monitored_systems',
+ };
+ billingState.upgradePricing.status = 'ready';
+ billingState.upgradePricing.data = {
+ title: 'Pricing',
+ description: 'Canonical pricing model',
+ plans: [
+ {
+ tierKicker: 'Pro+',
+ title: 'Pro+',
+ price: '$14.99',
+ period: '$129/year available too',
+ blurb: 'More room.',
+ features: [{ tone: 'check', html: 'Up to <strong>50 monitored systems</strong>' }],
+ buttons: [
+ {
+ kind: 'checkout',
+ className: 'btn btn-primary',
+ tier: 'pro_plus',
+ planKey: 'price_pro_plus_annual',
+ billingCycle: 'annual',
+ label: 'Buy Annual',
+ },
+ ],
+ },
+ ],
+ };
+
+ renderUpgradePanel(billingState, createBootstrap());
+
+ expect(document.getElementById('upgrade-billing-root')?.innerHTML).toContain(
+ 'Open this upgrade from Pulse Pro billing so Pulse Account can verify the secure upgrade handoff before checkout.',
+ );
+ expect(
+ (document.querySelector('[data-account-billing-action="upgrade-start-checkout"]') as HTMLButtonElement).disabled,
+ ).toBe(true);
+ });
});
diff --git a/internal/cloudcp/portal/frontend/src/billing_view.ts b/internal/cloudcp/portal/frontend/src/billing_view.ts
index 8854ca7e29..a74563a498 100644
--- a/internal/cloudcp/portal/frontend/src/billing_view.ts
+++ b/internal/cloudcp/portal/frontend/src/billing_view.ts
@@ -88,7 +88,9 @@ function renderUpgradePlansHTML(billingState: PortalBillingState): string {
return '';
}
+ var portalHandoffID = String(billingState.upgradePortalHandoffID || '').trim();
var checkoutDisabled = billingState.upgradeCheckout.pending ||
+ !portalHandoffID ||
billingState.upgradeCheckoutIntent.status === 'loading' ||
!String(billingState.upgradeCheckoutIntentID || '').trim() ||
billingState.upgradeCheckoutIntent.status !== 'ready';
@@ -152,7 +154,7 @@ export function renderUpgradePanel(billingState: PortalBillingState, _bootstrap:
if (billingState.upgradeCheckout.error) {
summaryItems.push('<div class="billing-status visible error">' + escapeText(billingState.upgradeCheckout.error) + '</div>');
}
- if (!portalHandoffID && !checkoutIntentID) {
+ if (!portalHandoffID) {
summaryItems.push(
'<div class="billing-status visible error">Open this upgrade from Pulse Pro billing so Pulse Account can verify the secure upgrade handoff before checkout.</div>',
);
@@ -160,7 +162,7 @@ export function renderUpgradePanel(billingState: PortalBillingState, _bootstrap:
summaryItems.push('<div class="billing-status visible">Verifying the secure Pulse Pro upgrade handoff...</div>');
} else if (checkoutIntentState.status === 'error') {
summaryItems.push('<div class="billing-status visible error">' + escapeText(checkoutIntentState.error || 'Failed to verify the secure Pulse Pro upgrade handoff.') + '</div>');
- } else if (checkoutIntentState.status === 'ready') {
+ } else if (checkoutIntentState.status === 'ready' && checkoutIntentID) {
summaryItems.push('<div class="billing-status visible success">Pulse Account will return completed checkout directly to Pulse Pro billing.</div>');
}
if (pricingState.status === 'loading' && !pricingState.data) {
diff --git a/internal/cloudcp/portal/frontend/src/runtime.test.ts b/internal/cloudcp/portal/frontend/src/runtime.test.ts
index d92496bf0f..27b24e0852 100644
--- a/internal/cloudcp/portal/frontend/src/runtime.test.ts
+++ b/internal/cloudcp/portal/frontend/src/runtime.test.ts
@@ -70,7 +70,16 @@ describe('portal runtime', function() {
expect(handoff.email).toBe('[email protected]');
expect(handoff.openBillingPanelID).toBe('upgrade-billing-panel');
expect(handoff.upgradePortalHandoffID).toBe('cph_signed');
- expect(handoff.upgradeCheckoutIntentID).toBe('');
+ expect(handoff.upgradeFeatureKey).toBe('');
+ });
+
+ it('blocks legacy checkout intent arrivals from acting as a trusted upgrade bootstrap', function() {
+ var handoff = readPortalRuntimeHandoff(
+ 'https://cloud.pulserelay.pro/portal?service=upgrade&checkout_intent_id=cki_legacy',
+ );
+
+ expect(handoff.openBillingPanelID).toBe('upgrade-billing-panel');
+ expect(handoff.upgradePortalHandoffID).toBe('');
expect(handoff.upgradeFeatureKey).toBe('');
});
@@ -86,7 +95,6 @@ describe('portal runtime', function() {
openBillingPanelID: 'refund-billing-panel',
upgradePortalHandoffID: '',
- upgradeCheckoutIntentID: '',
upgradeFeatureKey: '',
}
);
@@ -109,7 +117,6 @@ describe('portal runtime', function() {
email: '',
openBillingPanelID: 'upgrade-billing-panel',
upgradePortalHandoffID: 'cph_signed',
- upgradeCheckoutIntentID: '',
upgradeFeatureKey: '',
}
);
@@ -117,7 +124,6 @@ describe('portal runtime', function() {
expect(runtime.store.getShellState().activeSection).toBe('billing');
expect(runtime.store.getBillingState().openBillingPanelID).toBe('upgrade-billing-panel');
expect(runtime.store.getBillingState().upgradePortalHandoffID).toBe('cph_signed');
- expect(runtime.store.getBillingState().upgradeCheckoutIntentID).toBe('');
expect(runtime.store.getBillingState().upgradeFeatureKey).toBe('');
});
});
diff --git a/internal/cloudcp/portal/frontend/src/runtime.ts b/internal/cloudcp/portal/frontend/src/runtime.ts
index 96338c555e..4450216b0b 100644
--- a/internal/cloudcp/portal/frontend/src/runtime.ts
+++ b/internal/cloudcp/portal/frontend/src/runtime.ts
@@ -6,7 +6,6 @@ export interface PortalRuntimeHandoff {
email: string;
openBillingPanelID: string;
upgradePortalHandoffID: string;
- upgradeCheckoutIntentID: string;
upgradeFeatureKey: string;
}
@@ -33,14 +32,6 @@ function normalizeHandoffEmail(value: string | null): string {
return String(value || '').trim();
}
-function normalizeUpgradeCheckoutIntentID(
- value: string | null | undefined,
-): string {
- var trimmed = String(value || '').trim();
- if (!trimmed) return '';
- return /^[A-Za-z0-9_-]+$/.test(trimmed) ? trimmed : '';
-}
-
function normalizeUpgradePortalHandoffID(
value: string | null | undefined,
): string {
@@ -84,7 +75,6 @@ export function readPortalRuntimeHandoff(
email: normalizeHandoffEmail(params.get('email')),
openBillingPanelID: openBillingPanelID,
upgradePortalHandoffID: upgradePortalHandoffID,
- upgradeCheckoutIntentID: normalizeUpgradeCheckoutIntentID(params.get('checkout_intent_id')),
upgradeFeatureKey: normalizeUpgradeFeatureKey(params.get('feature')),
};
} catch {
@@ -92,7 +82,6 @@ export function readPortalRuntimeHandoff(
email: '',
openBillingPanelID: '',
upgradePortalHandoffID: '',
- upgradeCheckoutIntentID: '',
upgradeFeatureKey: '',
};
}
@@ -142,14 +131,12 @@ export function createPortalRuntime(
store.updateBillingState(function(billingState) {
billingState.openBillingPanelID = handoff.openBillingPanelID;
billingState.upgradePortalHandoffID = handoff.upgradePortalHandoffID;
- billingState.upgradeCheckoutIntentID = handoff.upgradeCheckoutIntentID;
billingState.upgradeFeatureKey = handoff.upgradeFeatureKey;
}, { notify: false });
- } else if (handoff.upgradeFeatureKey || handoff.upgradePortalHandoffID || handoff.upgradeCheckoutIntentID) {
+ } else if (handoff.upgradeFeatureKey || handoff.upgradePortalHandoffID) {
store.setActiveShellSection('billing');
store.updateBillingState(function(billingState) {
billingState.upgradePortalHandoffID = handoff.upgradePortalHandoffID;
- billingState.upgradeCheckoutIntentID = handoff.upgradeCheckoutIntentID;
billingState.upgradeFeatureKey = handoff.upgradeFeatureKey;
}, { notify: false });
}
diff --git a/internal/cloudcp/portal/frontend/src/shell_view.ts b/internal/cloudcp/portal/frontend/src/shell_view.ts
index 2019f143c3..241c78c942 100644
--- a/internal/cloudcp/portal/frontend/src/shell_view.ts
+++ b/internal/cloudcp/portal/frontend/src/shell_view.ts
@@ -1236,8 +1236,7 @@ export function renderAuthenticatedPortalHTML(context: ShellViewContext): string
var showSelfHostedUpgradeHandoff =
context.billingState.openBillingPanelID === 'upgrade-billing-panel' ||
!!normalizeUpgradeFeatureKey(context.billingState.upgradeFeatureKey) ||
- !!String(context.billingState.upgradePortalHandoffID || '').trim() ||
- !!String(context.billingState.upgradeCheckoutIntentID || '').trim();
+ !!String(context.billingState.upgradePortalHandoffID || '').trim();
var showSelfHostedBillingShell = showSelfHostedCommercial || showSelfHostedUpgradeHandoff;
var shellSections = visibleShellSections(context.bootstrap);
var preferredSection = context.activeSection || preferredPortalShellSection(context.bootstrap);
diff --git a/internal/cloudcp/portal/handlers_test.go b/internal/cloudcp/portal/handlers_test.go
index 789635d3db..5700ffcf72 100644
--- a/internal/cloudcp/portal/handlers_test.go
+++ b/internal/cloudcp/portal/handlers_test.go
@@ -1291,3 +1291,45 @@ func TestCommercialProxy_AllowsPricingAndCheckoutGETRequests(t *testing.T) {
t.Fatalf("body = %q", got)
}
}
+
+func TestCommercialProxy_AllowsPortalHandoffGETRequests(t *testing.T) {
+ upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method != http.MethodGet {
+ t.Fatalf("method = %s, want GET", r.Method)
+ }
+ if r.URL.Path != "/v1/checkout/portal-handoff" {
+ t.Fatalf("path = %s, want /v1/checkout/portal-handoff", r.URL.Path)
+ }
+ if got := r.URL.Query().Get("portal_handoff_id"); got != "cph_upgrade" {
+ t.Fatalf("portal_handoff_id = %q, want cph_upgrade", got)
+ }
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"portal_handoff_id":"cph_upgrade","checkout_intent_id":"cki_upgrade","feature":"max_monitored_systems"}`))
+ }))
+ defer upstream.Close()
+
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, PortalCommercialProxyPath+"v1/checkout/portal-handoff?portal_handoff_id=cph_upgrade", nil)
+ req.SetPathValue("commercial_path", "v1/checkout/portal-handoff")
+
+ HandleCommercialProxy(CommercialProxyConfig{BaseURL: upstream.URL})(rec, req)
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want %d (body=%q)", rec.Code, http.StatusOK, rec.Body.String())
+ }
+ if got := strings.TrimSpace(rec.Body.String()); got != `{"portal_handoff_id":"cph_upgrade","checkout_intent_id":"cki_upgrade","feature":"max_monitored_systems"}` {
+ t.Fatalf("body = %q", got)
+ }
+}
+
+func TestCommercialProxy_RejectsLegacyCheckoutIntentBootstrap(t *testing.T) {
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, PortalCommercialProxyPath+"v1/checkout/intent?checkout_intent_id=cki_legacy", nil)
+ req.SetPathValue("commercial_path", "v1/checkout/intent")
+
+ HandleCommercialProxy(CommercialProxyConfig{BaseURL: "https://license.pulserelay.pro"})(rec, req)
+
+ if rec.Code != http.StatusNotFound {
+ t.Fatalf("status = %d, want %d", rec.Code, http.StatusNotFound)
+ }
+}
diff --git a/tests/integration/tests/56-pulse-account-upgrade-bootstrap.spec.ts b/tests/integration/tests/56-pulse-account-upgrade-bootstrap.spec.ts
new file mode 100644
index 0000000000..107cf8bd18
--- /dev/null
+++ b/tests/integration/tests/56-pulse-account-upgrade-bootstrap.spec.ts
@@ -0,0 +1,107 @@
+import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
+
+import { expect, test } from "@playwright/test";
+
+const PORTAL_PREVIEW_PORT = "8876";
+const PORTAL_PREVIEW_URL = `http://127.0.0.1:${PORTAL_PREVIEW_PORT}`;
+const PORTAL_FRONTEND_DIR =
+ "/Volumes/Development/pulse/repos/pulse/internal/cloudcp/portal/frontend";
+
+async function waitForPortalPreview(url: string, timeoutMs: number) {
+ const deadline = Date.now() + timeoutMs;
+ while (Date.now() < deadline) {
+ try {
+ const response = await fetch(url);
+ if (response.ok) {
+ return;
+ }
+ } catch {
+ // Keep polling until the preview is ready.
+ }
+ await new Promise((resolve) => setTimeout(resolve, 200));
+ }
+ throw new Error(`Timed out waiting for Pulse Account preview at ${url}`);
+}
+
+async function stopPortalPreview(process: ChildProcessWithoutNullStreams | null) {
+ if (!process || process.killed) {
+ return;
+ }
+ await new Promise<void>((resolve) => {
+ const timer = setTimeout(() => {
+ process.kill("SIGKILL");
+ }, 2000);
+ process.once("exit", () => {
+ clearTimeout(timer);
+ resolve();
+ });
+ process.kill("SIGTERM");
+ });
+}
+
+test.describe.configure({ mode: "serial" });
+
+test.describe("Pulse Account upgrade bootstrap", () => {
+ let previewProcess: ChildProcessWithoutNullStreams | null = null;
+
+ test.beforeAll(async () => {
+ previewProcess = spawn(process.execPath, ["dev.mjs"], {
+ cwd: PORTAL_FRONTEND_DIR,
+ env: {
+ ...process.env,
+ PULSE_PORTAL_PREVIEW_PORT: PORTAL_PREVIEW_PORT,
+ },
+ stdio: ["ignore", "pipe", "pipe"],
+ });
+ previewProcess.stdout.on("data", () => {});
+ previewProcess.stderr.on("data", () => {});
+ await waitForPortalPreview(`${PORTAL_PREVIEW_URL}/healthz`, 30000);
+ });
+
+ test.afterAll(async () => {
+ await stopPortalPreview(previewProcess);
+ });
+
+ test("accepts the canonical portal handoff bootstrap", async ({ page }, testInfo) => {
+ test.skip(
+ testInfo.project.name.startsWith("mobile-"),
+ "Desktop-only billing continuity",
+ );
+
+ await page.goto(
+ `${PORTAL_PREVIEW_URL}/?scenario=managed&portal_handoff_id=cph_preview_upgrade`,
+ { waitUntil: "domcontentloaded" },
+ );
+
+ await expect(
+ page.getByText(
+ "Pulse Account will return completed checkout directly to Pulse Pro billing.",
+ ),
+ ).toBeVisible();
+ await expect(
+ page.getByText(
+ "Open this upgrade from Pulse Pro billing so Pulse Account can verify the secure upgrade handoff before checkout.",
+ ),
+ ).toHaveCount(0);
+ await expect(page.getByRole("button", { name: "Buy Annual" }).first()).toBeEnabled();
+ });
+
+ test("blocks the retired checkout-intent bootstrap path", async ({ page }, testInfo) => {
+ test.skip(
+ testInfo.project.name.startsWith("mobile-"),
+ "Desktop-only billing continuity",
+ );
+
+ await page.goto(
+ `${PORTAL_PREVIEW_URL}/?scenario=managed&service=upgrade&checkout_intent_id=cki_legacy`,
+ { waitUntil: "domcontentloaded" },
+ );
+
+ await expect(
+ page.getByText(
+ "Open this upgrade from Pulse Pro billing so Pulse Account can verify the secure upgrade handoff before checkout.",
+ ),
+ ).toBeVisible();
+ await expect(page.getByRole("button", { name: "Buy Annual" }).first()).toBeDisabled();
+ });
+});