Skip to content

feat(web): per-device pairing tokens — a revocable credential per phone#117

Merged
oratis merged 2 commits into
mainfrom
feat/device-pairing
Jun 19, 2026
Merged

feat(web): per-device pairing tokens — a revocable credential per phone#117
oratis merged 2 commits into
mainfrom
feat/device-pairing

Conversation

@oratis

@oratis oratis commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Stacked on #115#114#113. Retarget to main once those merge.

What

The iOS app needs each phone to have its own, revocable credential rather than sharing the global LISA_WEB_TOKEN. This adds per-device pairing tokens layered on top of the global token.

src/web/devices.ts:

  • mintDevice(name, platform) → a fresh token; only its SHA-256 hash is persisted (~/.lisa/devices.json). The raw token is returned once (for the QR).
  • verifyDeviceToken(presented) → constant-time match against stored hashes.
  • listDevices() (no hashes), revokeDevice(id), touchDevice(id) (lastSeen).

Auth gate (server.ts): a non-loopback request is now authorized by the global token or any non-revoked device token (and bumps that device's lastSeen). The global token still gates binding non-loopback; device tokens gate individual access.

Endpoints:

  • POST /api/pair/start (loopback-only) → { id, token, port, device } — the Mac shows the token as a QR.
  • GET /api/devices{ devices: [...] } (no hashes).
  • POST /api/devices/revoke {id} (loopback-only).

Verification

  • npm run typecheck + npm run build clean; 741 tests / 740 pass / 1 skip / 0 fail (6 new device-token tests: mint/verify, hash-not-persisted, revoke, list-excludes-hash, multi-device, corrupt-file).
  • Live end-to-end from a LAN IP (--host 0.0.0.0, global token set):
    • pair/start (loopback) mints a token; from remote → 403.
    • remote request with the device token (not the global) → 200.
    • wrong token → 401.
    • revoke (loopback) → 200; the revoked token → 401.
    • /api/devices never exposes tokenHash.

🤖 Generated with Claude Code

- src/web/devices.ts: mint / verify / revoke per-device tokens. Only the SHA-256 hash is stored (~/.lisa/devices.json); the raw token is returned once (for the QR); verification is constant-time.

- Auth gate now accepts the global LISA_WEB_TOKEN OR any non-revoked device token (and updates lastSeen on use), so a phone authenticates with its own revocable credential — not the shared secret.

- POST /api/pair/start (loopback-only) mints one; GET /api/devices lists them (no hashes); POST /api/devices/revoke (loopback-only) removes one.

Verified: typecheck + build clean; 741 tests pass (6 new); live-checked end-to-end from a LAN IP — a device token authenticates a remote request, a wrong token 401s, and revoke makes it 401 again.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
devices.json holds per-device token hashes — credentials — but was written
world-readable (644) in a 755 dir, below the project's own secret-handling bar.
Match env.ts's config.env handling: 0600 file in a 0700 dir, with a chmod
fallback to tighten any pre-existing loose file. Adds a test asserting the mode.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@oratis oratis changed the base branch from feat/roster-dedup-and-dispatch-status to main June 19, 2026 05:08
@oratis oratis merged commit df2dd15 into main Jun 19, 2026
1 check passed
@oratis oratis deleted the feat/device-pairing branch June 19, 2026 05:09
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