feat(auth): persist the GitHub user-to-server token from login - #6125
Merged
Conversation
Closes #6114 completeGitHubWebOAuth/pollGitHubDeviceFlow fetched a real GitHub user-to-server token during login, used it once to verify identity via GET /user, then discarded it -- so a CLI/AMS process had no way to authenticate git operations without a separately-configured GITHUB_TOKEN PAT set up outside loopover-mcp login entirely. Persist the token encrypted at rest (AES-256-GCM, same envelope as the existing BYOK/Linear key stores) in a new isolated auth_session_github_tokens table -- kept off the auth_sessions row itself so the session lookup used on every authenticated request never touches it. Expose it via a new session-scoped POST /v1/auth/github/token endpoint (never reachable by the static mcp/api identities, never cached, never bundled into any existing login response). revokeSession now deletes the stored token too, not just the loopover session. Missing TOKEN_ENCRYPTION_SECRET warns and continues rather than blocking login -- unlike the BYOK/Linear key stores there is no re-mint-on-demand fallback for a user's own OAuth token, so a silent skip would otherwise be undiagnosable later when AMS's token fetch comes up empty.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Bundle ReportChanges will increase total bundle size by 1.63kB (0.05%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: loopover-uiAssets Changed:
|
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (97.14%) is below the target coverage (99.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #6125 +/- ##
=======================================
Coverage 95.31% 95.31%
=======================================
Files 595 595
Lines 47100 47132 +32
Branches 15032 15038 +6
=======================================
+ Hits 44893 44924 +31
- Misses 1476 1477 +1
Partials 731 731
Flags with carried forward coverage won't be shown. Click here to find out more.
|
jony376
pushed a commit
to jony376/gittensory
that referenced
this pull request
Jul 15, 2026
This was referenced Jul 15, 2026
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.
Closes #6114
Summary
loopover-mcp login's device-flow/web-OAuth exchange minted a real GitHub user-to-server token, used it exactly once to verify identity (GET /user), then discarded it. AMS's git operations had no way to reuse it and required a separately-configuredGITHUB_TOKENPAT.TOKEN_ENCRYPTION_SECRET, reusingencryptSecret/decryptSecret) in a new isolated table (auth_session_github_tokens) — mirroringrepository_ai_keys/repository_linear_keys's existing pattern rather than a column onauth_sessionsitself, so the session lookup used on every authenticated request never touches it.POST /v1/auth/github/tokenendpoint fetches the live token on demand. Session-only (the staticmcp/apishared-secret identities are rejected), never cached (Cache-Control: no-store), never bundled into any existing login response.revokeSessionnow deletes the stored token too, not just the loopover session.TOKEN_ENCRYPTION_SECRETwarns and continues rather than blocking login — unlike the BYOK/Linear key stores (which throw), there's no re-mint-on-demand fallback for a user's own OAuth token the waysrc/orb/broker.tshas for installation tokens, so silently dropping it would leave AMS's later token-fetch failing with no diagnosable trail back to the cause.isProtectedPathwould have documented this new endpoint as public (it special-cased only/v1/auth/extension/sessionamong/v1/auth/*paths as requiring auth).Test plan
test/unit/auth-github-token.test.ts(16 tests): encrypted round-trip, no-op when no token supplied, warn-not-throw on missing encryption key, null (not throw) on wrong/rotated key, replace-on-reauth (not duplicate), revocation deletes the token, delete-when-absent is a no-op, never appears in the session-creation audit event, end-to-end persistence through both the device-flow and web-OAuth login paths, and the new route's auth gating / 404-when-unavailable / no-store header / telemetry-without-the-token-value.npx vitest runacross the new file +auth.test.ts+linear-key.test.ts+openapi.test.ts— all green.security.ts,github-oauth.ts, andrepositories.ts(verified via the raw v8 coverage JSON directly against the exact new line ranges, since the aggregate file-level percentage understates it forrepositories.ts— a ~8000-line file).npm run db:migrations:check/db:schema-drift:check/ui:openapi:check/ui:openapi:settings-parityall pass.npm run test:cigate green (twice — once pre-rebase, once post-rebase onto freshorigin/main).