Skip to content

fix: Device Token Scope Escalation via Rotate Endpoint#20703

Merged
mbelinky merged 2 commits intoopenclaw:mainfrom
coygeek:codex/aa-02-device-token-scope-escalation-2
Feb 20, 2026
Merged

fix: Device Token Scope Escalation via Rotate Endpoint#20703
mbelinky merged 2 commits intoopenclaw:mainfrom
coygeek:codex/aa-02-device-token-scope-escalation-2

Conversation

@coygeek
Copy link
Contributor

@coygeek coygeek commented Feb 19, 2026

Fix Summary

The device.token.rotate endpoint allows an authenticated device to escalate its own scopes beyond what was originally approved during pairing, enabling privilege escalation from a limited device role to full admin access.

Issue Linkage

Fixes #20702

Security Snapshot

  • CVSS v3.1: 8.1 (High)
  • CVSS v4.0: 8.6 (High)

Implementation Details

Files Changed

  • src/gateway/server-methods/devices.ts (+1/-1)
  • src/infra/device-pairing.test.ts (+23/-2)
  • src/infra/device-pairing.ts (+43/-6)

Technical Analysis

The vulnerability is reachable through a production code path where untrusted input can influence security-sensitive behavior without sufficient invariant enforcement. Current evidence indicates impact consistent with the summary: The device.token.rotate endpoint allows an authenticated device to escalate its own scopes beyond what was originally approved during pairing, enabling privilege escalation from a limited device role to full admin access.

Validation Evidence

  • Command: pnpm build && pnpm check && pnpm test
  • Status: passed

Risk and Compatibility

non-breaking; no known regression impact

AI-Assisted Disclosure

  • AI-assisted: yes
  • Model: GPT-5.3-Codex

Greptile Summary

Addresses device token scope escalation by introducing an approvedScopes field that preserves the originally approved scopes during device pairing and prevents unauthorized privilege escalation during token rotation.

Key changes:

  • Added approvedScopes field to track scopes approved at pairing time in src/infra/device-pairing.ts:58
  • Modified rotateDeviceToken to validate requested scopes against approvedScopes using scope implication logic in src/infra/device-pairing.ts:542-547
  • Added expandScopeImplications and scopesAllowWithImplications helpers to handle hierarchical scope relationships (e.g., operator.admin implies operator.read) in src/infra/device-pairing.ts:170-190
  • Removed automatic device.scopes mutation during rotation that previously allowed escalation in src/infra/device-pairing.ts:555-558 (removed lines)
  • Protected approvedScopes from modification via updatePairedDeviceMetadata in src/infra/device-pairing.ts:374 and src/infra/device-pairing.ts:392
  • Redacted approvedScopes from API responses to prevent information disclosure in src/gateway/server-methods/devices.ts:27
  • Added comprehensive test coverage for both down-scoping (allowed) and escalation (blocked) scenarios

Confidence Score: 5/5

  • This PR is safe to merge with high confidence - it properly fixes a critical security vulnerability without introducing new issues
  • The fix correctly implements defense-in-depth by: (1) introducing an immutable approvedScopes baseline that cannot be modified after approval, (2) validating all rotation requests against this baseline with proper scope implication handling, (3) returning null instead of throwing on unauthorized escalation attempts to prevent state mutation, (4) protecting the security-sensitive field from external modification, and (5) comprehensive test coverage that validates both the vulnerability fix and legitimate down-scoping scenarios. The implementation follows security best practices by making the validation logic explicit, adding redaction to prevent information disclosure, and ensuring state remains unchanged when attacks are blocked.
  • No files require special attention

Last reviewed commit: 93e73eb

Copy link
Contributor

@arosstale arosstale left a comment

Choose a reason for hiding this comment

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

Solid security fix. The approvedScopes baseline in the pairing record is the right anchor — it captures what was authorised during the pairing ceremony and can't be escalated past by the device itself. expandScopeImplications is correct for normalising before comparison. One small note: rotateDeviceToken returning null on escalation attempt rather than throwing means callers can silently ignore escalation failures — the server-methods/devices.ts handler catches this with if (!entry) and responds with INVALID_REQUEST, which is fine. LGTM.

@mbelinky mbelinky force-pushed the codex/aa-02-device-token-scope-escalation-2 branch from 93e73eb to 4f2c2ec Compare February 20, 2026 17:38
@mbelinky mbelinky merged commit 914a7c5 into openclaw:main Feb 20, 2026
10 checks passed
@mbelinky
Copy link
Contributor

Merged via squash.

Thanks @coygeek!

rodrigogs pushed a commit to rodrigogs/openclaw that referenced this pull request Feb 20, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Hansen1018 added a commit to Hansen1018/openclaw that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
vincentkoc pushed a commit that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
dgarson pushed a commit to dgarson/clawdbot that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mmyyfirstb pushed a commit to mmyyfirstb/openclaw that referenced this pull request Feb 21, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
obviyus pushed a commit to guirguispierre/openclaw that referenced this pull request Feb 22, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
mreedr pushed a commit to mreedr/openclaw-custom that referenced this pull request Feb 24, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky

(cherry picked from commit 914a7c5)

# Conflicts:
#	CHANGELOG.md
#	src/infra/device-pairing.ts
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky

(cherry picked from commit 914a7c5)

# Conflicts:
#	CHANGELOG.md
#	src/infra/device-pairing.test.ts
#	src/infra/device-pairing.ts
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 4f2c2ec
Co-authored-by: coygeek <65363919+coygeek@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Device Token Scope Escalation via Rotate Endpoint

3 participants