Repository navigation
feat(studio): TR-10 short-lived sessions with rotating refresh (onto main) - #1113
Merged
Merged
Conversation
…Egeria, sign-out ends refresh
Owner decision: "shorter TTL + refresh".
- Studio's session JWTs now live STUDIO_JWT_TTL_MINUTES (default 15) and
carry sid (one per sign-in, kept across refreshes) and auth_time.
STUDIO_SESSION_MAX_HOURS (default 8) caps a session counted from
sign-in; the Egeria token still caps every JWT.
- POST /api/auth/refresh mints a new JWT for the same sid only when
every check holds:
- the presented JWT is valid and not signed out;
- the session is under its maximum age;
- its Egeria token hasn't expired;
- Egeria still accepts the token, asked as the user with a
no-password client (egeria.check_signin -> get_my_profile).
Egeria refusing it is a 401 and also signs the session out here.
Egeria unreachable is a 503 with no new JWT, and the session runs on.
- Logout carries the JWT and revokes its sid. From then on every JWT of
that session is refused on every non-public path (StudioLoginMiddleware
over trellis-auth's gate, and current_user) and can't be refreshed. A
JWT without a sid is refused too, so deploying this signs current
sessions out once.
- The page refreshes in the last third of a JWT's life (30 s to 5 min
before exp) only if it was used while that JWT was live; an untouched
tab lapses. The decision is session_refresh.js, pure and node-tested.
A 401/403 ends the session. The new JWT reaches the EA panel by the
existing studio:session event, and EA swaps a same-sid JWT in quietly
(no app restart, no sidebar reload).
- trellis-auth create_access_token gains keyword-only ttl and
extra_claims (additive; extra claims can't replace the contract).
Read-back advisories:
- EA open_in_studio: a lock per (user, label) is held across the check
and the save, so a double click or two tabs on one EA save once.
Still not atomic across processes (noted in the code).
- A signed-out JWT re-sent after its exp is refused by Studio's
/api/auth/me and by EA's whoami. EA can't see Studio's sign-outs, so
at EA a signed-out JWT works until its exp (at most the TTL).
Limits (sessions.py): revocations live in process memory (a restart
forgets them; short JWTs bound that). No session outlives the Egeria
token it signed in with (about an hour on laz), because Studio holds no
password to renew it.
Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
…sion
The Architect's read-back criteria, sent ahead.
- Sign-in returns an access JWT (15 min by default) and a refresh token:
opaque, random, known to Studio only by its SHA-256, and bound to one
session's sid, its user and the Egeria token it signed in with.
- POST /api/auth/refresh {refresh_token} now trades the refresh token for
a new access token AND a new refresh token. Each refresh token works
once (rotation). Presenting a used one is a replay: every access and
refresh token of that session is revoked, and the answer is 401.
- Identity can't change: the new access token is minted for the refresh
token's own user. An access token sent with the request must have the
same sub and sid, or the session is revoked.
- Re-checks are as before (maximum age; Egeria token unexpired; Egeria
still accepts it, asked as the user). If Egeria refuses it, the
session is revoked and the answer is 401. If Egeria can't be asked,
it's a 503 and the refresh token stays unused, so a retry isn't
mistaken for a replay.
- /api/auth/refresh is a public path, gated by its refresh token, so a
page whose access token just expired can still refresh. An expired
access token alone is a 401 everywhere, never anonymous.
- Logout takes the access token, the refresh token or both (an expired
access token still works for this), revokes the sid and drops its
refresh tokens.
- The page keeps the refresh token in sessionStorage beside the JWT,
replaces both on refresh, sends both on sign-out and clears both. It
never hands the refresh token to EA.
Tests: one per criterion, including rotation, replay revoking the chain,
a mismatched identity, an Egeria refusal, an expired Egeria token, sign-
out by either token, and an expired access token with no refresh is 401.
Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
…s tabs Read-back advisory on d8f5603. A double-fire would send one refresh token twice, which Studio reads as a replay and revokes the session. - singleFlight (session_refresh.js, node-tested): calls made while a refresh is running share it. - Across tabs (a duplicated tab copies sessionStorage, so it holds the same refresh token), refreshes run one at a time under a Web Lock ('studio-refresh'). Inside the lock the page re-reads its token and re-decides, so a tab another tab has just rotated doesn't send a stale refresh token. - Tabs of one session tell each other on a BroadcastChannel when they rotate (the new tokens) or end the session (a refusal, or sign-out), matched by sid, so news about another session is ignored. Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.com>
The TR-10 merge left .env.example with the removed STUDIO_JWT_TTL_HOURS and without the two settings that replace it, so test_every_setting_studio_reads_is_in_the_example failed. This was a semantic conflict with TR-48, not a textual one. Document STUDIO_JWT_TTL_MINUTES (default 15) and STUDIO_SESSION_MAX_HOURS (default 8) instead. Studio tests: 116 passed, 7 skipped, both env ways. Signed-off-by: Dan Wolfson <dan.wolfson@pdr-associates.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.
TR-10 (Dan, 2026-11-18: "TR-10 Merge it"). This brings the Studio session-refresh work,
claude/tr10-studio-session-refresh(48b3268, Architect PASS 2026-11-15), onto current main. It was never merged.What changes
STUDIO_JWT_TTL_MINUTES, default 15.STUDIO_SESSION_MAX_HOURSafter sign-in (default 8); then you sign in again.create_access_tokentakes a TTL and extra claims.The merge
auth.pyandtest_auth.pymerged automatically, and the Architect found the result right. TR-10 changedcreate_access_token; main changedvalidate_egeria_token(TR-24). Studio's refresh re-check now uses main's TR-24 validation..env.examplestill listed the removedSTUDIO_JWT_TTL_HOURS. Fixed in 2ad17b5, which documents the two new settings.Checks
.env.exampletest, which 2ad17b5 fixes.STUDIO_*names, so the rename changes nothing there.🤖 Generated with Claude Code