spike(auth): short-lived scoped app tokens (#1069 / #799 P3)#1071
Draft
imajin-jin wants to merge 1 commit into
Draft
spike(auth): short-lived scoped app tokens (#1069 / #799 P3)#1071imajin-jin wants to merge 1 commit into
imajin-jin wants to merge 1 commit into
Conversation
Open
12 tasks
|
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.



Spike — short-lived scoped app tokens (#1069 / #799 P3)
Draft / spike. Implements the scoped app-token primitive from the #1069 design so #799's "delegated session token minted from handshake (scoped, time-limited)" (P3) has a concrete shape. Not for merge as-is — see "Not in this spike" below.
What this adds
1. App token sign/verify —
apps/kernel/src/lib/auth/jwt.tscreateAppToken()/verifyAppToken(). Reuses the existing kernel EdDSA keypair. Tokens aretyp: app+jwt(so a session token can't be replayed as an app token), ~10 min TTL, claims:sub=userDid,azp=appDid,scope(space-delimited),aud,attestationId.2. Mint endpoint —
POST /auth/api/apps/token${appDid}:${attestationId}:${nonce}:${timestamp}; kernel resolves the app DID's public key (createDbResolver) and verifies via the existingverifySignature. Rejects stale/future timestamps (60s window) and short nonces.app.authorizedattestation checks as/apps/validate(existence,revokedAt, scope grant), and mints the token. Optionalscopenarrows to a single granted scope.3. Stateless verify endpoint —
POST /auth/api/apps/token/verifyAppAuthContextshape.4.
requireAppAuthBearer fast-path —packages/auth/src/require-app-auth.tsAuthorization: Bearer <app-token>→verifyBearerAppToken(). Falls back to the legacyX-App-DID+X-App-Authorization(static attestationId) path during migration. No existing behavior removed.Why this matters for third-party apps
The static
X-App-Authorization: <attestationId>bearer is long-lived and replayable. This replaces it with a short-lived, app-key-bound token while keeping the existing consent/scope/revocation system (#799 P1) authoritative. Short TTL bounds the revocation window without a per-call DB lookup.Verification
tsc --noEmitacrossapps/kernel: 0 errors.NOT in this spike (follow-ups on #1069)
domain=.imajin.aito host-only, and the staged rollout. This is the other half of Security: app subdomain cookie isolation (scoped tokens, not shared parent-domain cookie) #1069 and the actual security fix; the token is the prerequisite.verifyBearerAppTokencurrently calls the kernel/token/verifyendpoint (stateless, but still a round-trip). Moving jose + the published kernel public key into@imajin/authremoves it entirely.Related: #1069, #799, #244