Repository navigation
fix(licensing): start a new registration when /license/register gets another redirect_uri - #2816
Conversation
…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.
Reviewer's GuideData structuresAdd runtime state to remember the redirect URI associated with a pending registration.
APIReturn the cached registration URL only when the incoming redirect URI matches the one associated with it; otherwise initialize a registration with the requested URI.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/api/routes/license.router.ts" line_range="30" />
<code_context>
+
+ // 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 });
}
</code_context>
<issue_to_address>
**Concurrent requests create duplicate links**
When two requests for the same redirect URI arrive before either registration request completes, both handlers pass the `rc.registerUrl` cache check and call `initRegistration`, so the licensing server issues separate links; the later completion replaces the cached link, leaving the earlier caller's link absent from the cache.
Track and reuse an in-flight registration for each redirect URI so concurrent requests share its result.
Also at `src/licensing/runtime.ts:479`.
</issue_to_address>
### Comment 2
<location path="src/licensing/runtime.ts" line_range="479" />
<code_context>
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;
}
</code_context>
<issue_to_address>
**Older response replaces newer cache**
When overlapping requests use different redirect URIs, and the newer request completes before the older one, `initRegistration` writes every response unconditionally, so an older request that finishes last replaces the newer request's cached URL and redirect URI. A later caller for the newer URI starts another registration instead of reusing its still-pending link.
Serialize registration updates or guard cache writes so a response cannot overwrite state from a newer request.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and a request with a different redirect_uri now creates a new remote registration and returns its link, so the registration flow can be rebound to a different callback while an earlier link may still exist. Reverting prevents future rebindings but does not retract links or registrations already issued.
Blocking findings: src/api/routes/license.router.ts:30, src/licensing/runtime.ts:479
📋 Description
GET /license/registercached the pending registration link and returned it to every caller. Theredirect_uriis bound to the registration on the licensing server when it starts, so after one direct call (noredirect_uri), the manager login (/manager/login, which sendsredirect_uri=<host>/manager/license/callback) received the same link: the user logged in, landed on the licensing success page with a code and never came back to the manager.The instance now remembers the
redirect_uriof the pending link and reuses it only for a caller asking for the same one; otherwise it starts a new registration.🧪 Type of Change
🧪 Testing
Local licensing server + API bundle pointing to it: direct
GET /license/register, then twice with the managerredirect_uri, then login with the manager link:develop/manager/license/callback?code=…,/license/activate→ activetsc --noEmit,eslint(pre-commit) andnpm run build+lint:check(pre-push)✅ Checklist
Summary by Sourcery
Bug Fixes:
redirect_uri, while reusing the pending link for matching redirect URIs.