Skip to content

Harden client retry path, refresh-scope grant, and tidy tool/OAuth internals - #6

Merged
SunsetDrifter merged 4 commits into
netbirdio:mainfrom
SunsetDrifter:fix/thermos-findings
Jul 24, 2026
Merged

SunsetDrifter merged 4 commits into
netbirdio:mainfrom
SunsetDrifter:fix/thermos-findings

Conversation

@SunsetDrifter

@SunsetDrifter SunsetDrifter commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

Four small, independent hardening/cleanup changes to the MCP server.

Cap honored Retry-After and decompose the client retry loop

The NetBird API client honored an upstream Retry-After verbatim, and the backoff sleep ran outside the request abort/timeout guard — so a misbehaving or compromised (but allowlisted) upstream returning e.g. Retry-After: 86400 could stall a call ~24h, well past NETBIRD_TIMEOUT_MS. Every honored delay is now clamped to a named MAX_BACKOFF_MS, so total call time stays bounded regardless of what the upstream sends. The same change decomposes request<T>() into fetchOnce/decideRetry/backoff: the retry decision lives in one place, the terminal throw-on-exhausted-retries is explicit rather than fall-through, and a redundant clearTimeout is removed.

Reject scope widening on the OAuth refresh grant

exchangeRefreshToken honored whatever scopes the client requested, with no check against the originally granted set — a client could widen scope on refresh, which RFC 6749 §6 forbids. It now rejects any requested scope outside the originally granted set with InvalidScopeError; no-scope and subset refreshes still succeed. The authorization-code exchange is unchanged (its scopes come from the stored code and are not client-controllable).

Quarantine the tool-registration type cast

The tool registry repeated the same as unknown as ToolCallback<Args> cast and registerTool skeleton across three functions. A single private register<Args>() primitive now owns the guard wrap and the lone cast; registerRead/registerMutation/registerDelete become cast-free config builders. Behavior is unchanged.

Simplify the OAuth login render path

The login decision object is already structurally a LoginPageParams (OAuthChallenge/OAuthLoginError are { kind } & LoginPrefill), so sendPage no longer hand-rebuilds the six prefill fields — it passes the decision straight to renderLoginPage. Behavior-preserving.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Bound total call time against a hostile/misbehaving upstream: every
honored delay is clamped to MAX_BACKOFF_MS, so a large Retry-After can
no longer stall a request past NETBIRD_TIMEOUT_MS. Decompose request<T>
into fetchOnce/decideRetry/backoff — one retry decision, explicit
throw-on-exhausted-retries, and the redundant catch-block clearTimeout
removed. Test drives a 429 with Retry-After: 86400 and asserts the cap.
exchangeRefreshToken now rejects any requested scope not in the
originally granted set (InvalidScopeError), per RFC 6749 §6; no-scope
and subset refreshes still succeed. exchangeAuthorizationCode is
unchanged (its scopes come from the stored code). Tests cover all three.
Single private register<Args>() owns the guard wrap and the lone
'as unknown as ToolCallback<Args>' cast; registerRead/Mutation/Delete
become cast-free config builders. Behavior unchanged.
The decision object is already structurally LoginPageParams
(OAuthChallenge/OAuthLoginError = { kind } & LoginPrefill), so drop the
hand-rebuilt six-field prefill in sendPage. Behavior-preserving.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@SunsetDrifter, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ec20e0dd-b241-4d2b-ba57-7a73cea7f4d7

📥 Commits

Reviewing files that changed from the base of the PR and between a4bdba4 and 212a4e4.

📒 Files selected for processing (6)
  • src/netbird/client.ts
  • src/oauth/core.ts
  • src/oauth/provider.ts
  • src/tools/registry.ts
  • test/client.test.ts
  • test/oauthCore.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SunsetDrifter
SunsetDrifter merged commit 36e9371 into netbirdio:main Jul 24, 2026
2 checks passed
@SunsetDrifter
SunsetDrifter deleted the fix/thermos-findings branch July 24, 2026 15:42
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