feat(web): per-device pairing tokens — a revocable credential per phone#117
Merged
Conversation
- 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>
This was referenced Jun 19, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'slastSeen). 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 buildclean; 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).--host 0.0.0.0, global token set):pair/start(loopback) mints a token; from remote → 403.revoke(loopback) → 200; the revoked token → 401./api/devicesnever exposestokenHash.🤖 Generated with Claude Code