Skip to content

fix(auth): surface distinct scope-mismatch reason for device token failures#79295

Closed
hclsys wants to merge 1 commit into
openclaw:mainfrom
hclsys:fix/auth-scope-mismatch-error-code-79292
Closed

fix(auth): surface distinct scope-mismatch reason for device token failures#79295
hclsys wants to merge 1 commit into
openclaw:mainfrom
hclsys:fix/auth-scope-mismatch-error-code-79292

Conversation

@hclsys

@hclsys hclsys commented May 8, 2026

Copy link
Copy Markdown

Summary

When verifyDeviceToken returns reason: "scope-mismatch" (the token's approved scopes do not cover the requested connection scopes), the auth pipeline collapsed this into the generic device_token_mismatch error and message — misleading clients into rotating/reissuing a perfectly valid token.

  • Expand VerifyDeviceTokenResult type to include reason?: string
  • Propagate scope-mismatch as a distinct device_token_scope_mismatch reason instead of collapsing it
  • Add AUTH_DEVICE_TOKEN_SCOPE_MISMATCH error detail code to ConnectErrorDetailCodes
  • Add "device_token_scope_mismatch" message case: "unauthorized: device token scope mismatch (re-pair this device to request the current scope set)"
  • Add test: verifyDeviceToken returning scope-mismatchauthResult.reason === "device_token_scope_mismatch"

Fixes #79292.

Root cause (from issue)

macOS/iOS/Control UI clients request 5 scopes including operator.admin and operator.pairing. Bootstrap token issuance strips those two (the allowlist only has 4), so the stored device token has 4 scopes. On reconnect with 5 scopes, verifyDeviceToken at line 896/900 of device-pairing.ts returns { ok: false, reason: "scope-mismatch" }. resolveConnectAuthDecision dropped the reason field (the local VerifyDeviceTokenResult type was { ok: boolean }) and emitted device_token_mismatch — the wrong diagnosis.

Test plan

  • src/gateway/server/ws-connection/auth-context.test.ts — new test: scope-mismatch reason propagates as device_token_scope_mismatch; all 30 tests pass
  • src/gateway/protocol/connect-error-details.test.ts — all 26 tests pass
  • No callers of formatGatewayAuthFailureMessage or readConnectAuthDecisionErrorDetailCode need changes — additive switch case

🤖 Generated with Claude Code

…ilures

When verifyDeviceToken returns reason="scope-mismatch" (the device token's
approved scopes do not cover the requested connection scopes), the auth
pipeline previously collapsed this into the generic device_token_mismatch
error, causing clients to rotate/reissue a perfectly valid token.

Surface a distinct device_token_scope_mismatch reason and error message
("re-pair this device to request the current scope set") so clients can
take the right corrective action. Adds AUTH_DEVICE_TOKEN_SCOPE_MISMATCH
error detail code for protocol-level classification.

Fixes openclaw#79292.
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: XS r: too-many-prs Auto-close: author has more than twenty active PRs. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 8, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because the author has more than 20 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

@openclaw-barnacle openclaw-barnacle Bot closed this May 8, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing this PR because the author has more than 20 active PRs in this repo. Please reduce the active PR queue and reopen or resubmit once it is back under the limit. You can close your own PRs to get back under the limit.

BunsDev added a commit that referenced this pull request May 11, 2026
Preserve full shared-token operator sessions while reusing bootstrap/cached device-token scopes for handoff reconnects.

Surface device-token scope mismatches as AUTH_SCOPE_MISMATCH and stop reconnect retry loops without clearing valid stored tokens.

Fixes #79292.
Supersedes #79314, #79296, #79295.
steipete pushed a commit that referenced this pull request May 12, 2026
Preserve full shared-token operator sessions while reusing bootstrap/cached device-token scopes for handoff reconnects.

Surface device-token scope mismatches as AUTH_SCOPE_MISMATCH and stop reconnect retry loops without clearing valid stored tokens.

Fixes #79292.
Supersedes #79314, #79296, #79295.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Preserve full shared-token operator sessions while reusing bootstrap/cached device-token scopes for handoff reconnects.

Surface device-token scope mismatches as AUTH_SCOPE_MISMATCH and stop reconnect retry loops without clearing valid stored tokens.

Fixes openclaw#79292.
Supersedes openclaw#79314, openclaw#79296, openclaw#79295.
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
Preserve full shared-token operator sessions while reusing bootstrap/cached device-token scopes for handoff reconnects.

Surface device-token scope mismatches as AUTH_SCOPE_MISMATCH and stop reconnect retry loops without clearing valid stored tokens.

Fixes openclaw#79292.
Supersedes openclaw#79314, openclaw#79296, openclaw#79295.
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
Preserve full shared-token operator sessions while reusing bootstrap/cached device-token scopes for handoff reconnects.

Surface device-token scope mismatches as AUTH_SCOPE_MISMATCH and stop reconnect retry loops without clearing valid stored tokens.

Fixes openclaw#79292.
Supersedes openclaw#79314, openclaw#79296, openclaw#79295.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime r: too-many-prs Auto-close: author has more than twenty active PRs. size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(auth): operator scope mismatch silently rejected as device token mismatch

1 participant