Skip to content

fix(licensing): start a new registration when /license/register gets another redirect_uri - #2816

Merged
daniloleonecarneiro merged 1 commit into
developfrom
fix/license-register-honors-redirect
Dec 2, 2026
Merged

daniloleonecarneiro merged 1 commit into
developfrom
fix/license-register-honors-redirect

Conversation

@daniloleonecarneiro

@daniloleonecarneiro daniloleonecarneiro commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

📋 Description

GET /license/register cached the pending registration link and returned it to every caller. The redirect_uri is bound to the registration on the licensing server when it starts, so after one direct call (no redirect_uri), the manager login (/manager/login, which sends redirect_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_uri of the pending link and reuses it only for a caller asking for the same one; otherwise it starts a new registration.

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)

🧪 Testing

Local licensing server + API bundle pointing to it: direct GET /license/register, then twice with the manager redirect_uri, then login with the manager link:

develop this branch
link for the manager same as the direct one new link
second manager call same link same manager link (still cached)
after login success page with the code, instance inactive redirect to /manager/license/callback?code=…, /license/activate → active
  • tsc --noEmit, eslint (pre-commit) and npm run build + lint:check (pre-push)

✅ Checklist

  • I have performed a self-review of my code
  • My changes generate no new warnings

Summary by Sourcery

Bug Fixes:

  • Start a new license registration when a request uses a different redirect_uri, while reusing the pending link for matching redirect URIs.

…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.
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Data structures

Add runtime state to remember the redirect URI associated with a pending registration.

  • src/licensing/runtime.ts L42, L479

API

Return the cached registration URL only when the incoming redirect URI matches the one associated with it; otherwise initialize a registration with the requested URI.

  • src/api/routes/license.router.ts L26-30, L35 (removed lines)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/api/routes/license.router.ts Resolved
Comment thread src/licensing/runtime.ts Resolved
@daniloleonecarneiro
daniloleonecarneiro merged commit 49898ff into develop Dec 2, 2026
5 checks passed
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