Repository navigation
fix(server): T3 Connect devices get new permissions after an update #17308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kroqdotdev
wants to merge
2
commits into
pingdotgg:main
Choose a base branch
from
kroqdotdev:fix/revoke-legacy-t3-connect-sessions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
81 changes: 81 additions & 0 deletions
81
apps/server/src/persistence/Migrations/061_RevokeLegacyCloudConnectSessions.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { assert, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as SqlClient from "effect/sql/SqlClient"; | ||
| import * as TestClock from "effect/testing/TestClock"; | ||
| import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient"; | ||
|
|
||
| import { runMigrations } from "../Migrations.ts"; | ||
|
|
||
| const now = "2026-10-08T20:00:00.000Z"; | ||
| // Minted for a current client by a server from before the split. | ||
| const preSplit = [ | ||
| "orchestration:read", | ||
| "orchestration:operate", | ||
| "terminal:operate", | ||
| "review:write", | ||
| "relay:read", | ||
| ]; | ||
| // An older client narrows its request to the scopes it knows. | ||
| const narrowedPreSplit = [ | ||
| "orchestration:read", | ||
| "orchestration:operate", | ||
| "terminal:operate", | ||
| "relay:read", | ||
| ]; | ||
| const standard = [ | ||
| "orchestration:read", | ||
| "orchestration:operate", | ||
| "terminal:operate", | ||
| "filesystem:read", | ||
| "filesystem:write", | ||
| "relay:read", | ||
| ]; | ||
|
|
||
| it.layer(NodeSqliteClient.layer({ filename: ":memory:" }))( | ||
| "061_RevokeLegacyCloudConnectSessions", | ||
| (it) => { | ||
| it.effect("revokes only live T3 Connect sessions minted before the scope split", () => | ||
| Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient; | ||
| yield* runMigrations({ toMigrationInclusive: 60 }); | ||
| const insert = ( | ||
| id: string, | ||
| subject: string, | ||
| scopes: ReadonlyArray<string>, | ||
| expiresAt: string, | ||
| ) => | ||
| sql` | ||
| INSERT INTO auth_sessions (session_id, subject, scopes, method, issued_at, expires_at) | ||
| VALUES (${id}, ${subject}, ${JSON.stringify(scopes)}, 'dpop-access-token', | ||
| '2026-10-08T19:39:38.320Z', ${expiresAt}) | ||
| `; | ||
| yield* insert("legacy-connect", "cloud-connect", preSplit, "2026-10-08T20:39:38.320Z"); | ||
| yield* insert( | ||
| "narrowed-connect", | ||
| "cloud-connect", | ||
| narrowedPreSplit, | ||
| "2026-10-08T20:39:38.320Z", | ||
| ); | ||
| yield* insert("current-connect", "cloud-connect", standard, "2026-10-08T20:39:38.320Z"); | ||
| yield* insert("expired-connect", "cloud-connect", preSplit, "2026-10-08T19:00:00.000Z"); | ||
| // A paired client keeps the grant the user chose, even a pre-split one. | ||
| yield* insert("paired", "one-time-token", preSplit, "2026-11-07T19:39:38.320Z"); | ||
|
|
||
| yield* TestClock.setTime(Date.parse(now)); | ||
| yield* runMigrations({ toMigrationInclusive: 61 }); | ||
|
|
||
| const rows = yield* sql<{ readonly sessionId: string; readonly revokedAt: string | null }>` | ||
| SELECT session_id AS "sessionId", revoked_at AS "revokedAt" | ||
| FROM auth_sessions ORDER BY session_id | ||
| `; | ||
| assert.deepStrictEqual(rows, [ | ||
| { sessionId: "current-connect", revokedAt: null }, | ||
| { sessionId: "expired-connect", revokedAt: null }, | ||
| { sessionId: "legacy-connect", revokedAt: now }, | ||
| { sessionId: "narrowed-connect", revokedAt: now }, | ||
| { sessionId: "paired", revokedAt: null }, | ||
| ]); | ||
| }), | ||
| ); | ||
| }, | ||
| ); |
40 changes: 40 additions & 0 deletions
40
apps/server/src/persistence/Migrations/061_RevokeLegacyCloudConnectSessions.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import * as DateTime from "effect/DateTime"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as SqlClient from "effect/sql/SqlClient"; | ||
|
|
||
| // The scope vocabulary before permissions were split. Frozen here so later | ||
| // scope changes cannot alter which sessions this migration matched. | ||
| const preSplitScopes = JSON.stringify([ | ||
| "orchestration:read", | ||
| "orchestration:operate", | ||
| "terminal:operate", | ||
| "review:write", | ||
| "access:read", | ||
| "access:write", | ||
| "relay:read", | ||
| "relay:write", | ||
| ]); | ||
|
|
||
| /** | ||
| * T3 Connect sessions carry whatever grant the server chose when it minted | ||
| * them, not one the user picked. Sessions minted before the split hold only | ||
| * the broad scopes, which no longer imply file access and the other newly | ||
| * separated permissions. Revoking them makes clients mint a replacement through | ||
| * the normal cloud flow, which receives the current standard grant. | ||
| */ | ||
| export default Effect.gen(function* () { | ||
| const sql = yield* SqlClient.SqlClient; | ||
| const now = DateTime.formatIso(yield* DateTime.now); | ||
|
|
||
| yield* sql` | ||
| UPDATE auth_sessions | ||
| SET revoked_at = ${now} | ||
| WHERE subject = 'cloud-connect' | ||
| AND revoked_at IS NULL | ||
| AND expires_at > ${now} | ||
| AND NOT EXISTS ( | ||
| SELECT 1 FROM json_each(auth_sessions.scopes) | ||
| WHERE value NOT IN (SELECT value FROM json_each(${preSplitScopes})) | ||
| ) | ||
| `; | ||
| }); | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.