From f50a1d750d986ae296824e4886e184b898263a4f Mon Sep 17 00:00:00 2001 From: Danilo Leone Date: Wed, 2 Dec 2026 13:24:29 -0300 Subject: [PATCH] fix(licensing): start a new registration when /license/register gets another redirect_uri The pending registration link was cached and returned to every caller. The redirect_uri is bound to the registration when it starts, so after a direct call without redirect_uri the manager login received the same link, ended on the licensing success page with the code and never returned to the manager. Reuse the pending link only for the same redirect_uri. --- src/api/routes/license.router.ts | 7 +++++-- src/licensing/runtime.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/api/routes/license.router.ts b/src/api/routes/license.router.ts index 7b1bf3eaf6..ace01acc57 100644 --- a/src/api/routes/license.router.ts +++ b/src/api/routes/license.router.ts @@ -23,12 +23,15 @@ export function buildLicenseRouter(rc: RuntimeContext): Router { return res.status(200).json({ status: 'active', message: 'License is already active' }); } - if (rc.registerUrl) { + const redirectUri = (req.query.redirect_uri as string) || undefined; + + // The redirect_uri is bound to the registration when it starts, so a pending + // link is only reusable by a caller asking for the same redirect. + if (rc.registerUrl && rc.registerRedirectUri === (redirectUri ?? '')) { return res.status(200).json({ status: 'pending', register_url: rc.registerUrl }); } try { - const redirectUri = (req.query.redirect_uri as string) || undefined; const url = await initRegistration(rc, redirectUri); logger.info(`Registration URL issued: ${url}`); return res.status(200).json({ status: 'pending', register_url: url }); diff --git a/src/licensing/runtime.ts b/src/licensing/runtime.ts index f99d026bc0..641359d930 100644 --- a/src/licensing/runtime.ts +++ b/src/licensing/runtime.ts @@ -39,6 +39,7 @@ export class RuntimeContext { public version: string; public registerUrl = ''; public registerToken = ''; + public registerRedirectUri = ''; private active = false; private ctxHash: Buffer = Buffer.alloc(32); @@ -475,6 +476,7 @@ export async function initRegistration(rc: RuntimeContext, redirectUri?: string) const resp = await postUnsigned<{ register_url: string; token: string }>('/v1/register/init', payload); rc.registerUrl = resp.data?.register_url ?? ''; rc.registerToken = resp.data?.token ?? ''; + rc.registerRedirectUri = redirectUri ?? ''; return rc.registerUrl; }