Skip to content

feat: add verification for v2 auth#3155

Merged
Salazareo merged 1 commit into
mainfrom
DS/put-1015
May 26, 2026
Merged

feat: add verification for v2 auth#3155
Salazareo merged 1 commit into
mainfrom
DS/put-1015

Conversation

@Salazareo
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.52%
⬆️ +0.13%
13401 / 18735
🔵 Statements 69.95%
⬆️ +0.14%
14154 / 20233
🔵 Functions 70.38%
⬆️ +0.10%
2217 / 3150
🔵 Branches 59.63%
⬆️ +0.20%
9002 / 15095
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/backend/server.ts 50.13%
🟰 ±0%
35.49%
🟰 ±0%
43.58%
🟰 ±0%
51.11%
🟰 ±0%
88-89, 103-108, 123-129, 174-187, 214-222, 245-246, 249-258, 261-265, 273, 276, 279, 285, 309, 316-322, 325-376, 399-427, 444-472, 486-488, 507-511, 534, 549-551, 561-566, 569-575, 578-584, 587-593, 603-605, 616, 620-622, 637, 643-679, 692-712, 719-720, 751-788
src/backend/core/http/expressAugmentation.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
src/backend/core/http/middleware/authProbe.ts 96%
⬆️ +1.18%
88.05%
⬆️ +2.09%
100%
🟰 ±0%
98.57%
⬆️ +0.43%
197, 203, 209
src/backend/core/http/middleware/gates.ts 89.18%
⬆️ +0.30%
89.74%
⬆️ +1.17%
94.11%
🟰 ±0%
89.18%
⬆️ +0.30%
124-139
src/backend/services/auth/AuthService.ts 79.94%
⬆️ +3.98%
67.39%
⬆️ +5.79%
87.03%
⬆️ +2.13%
83.88%
⬆️ +3.74%
75, 79, 118, 238, 240, 366-379, 388, 390, 406, 415-420, 438, 450, 480-481, 484-486, 489-494, 500-501, 512, 524, 526, 532, 613, 679, 814-816, 917, 996-998, 1056-1059, 1079, 1099-1103, 1106, 1109-1111, 1126, 1129, 1146-1182
src/backend/services/socket/SocketService.ts 40.57%
⬆️ +6.17%
31.39%
⬆️ +11.66%
42.85%
⬆️ +4.39%
43.75%
⬆️ +6.36%
46-56, 72, 76-78, 88, 94-134, 139, 142-144, 147-181, 186, 188-212, 220, 227, 233, 259-273, 285
src/backend/stores/session/SessionStore.js 79.67%
⬆️ +1.46%
75%
⬆️ +0.98%
71.05%
⬆️ +0.78%
81.48%
⬆️ +1.36%
90, 234, 317-319, 353, 365-367, 399-432, 493, 499, 505, 548-549, 558, 564, 578, 583, 631
Generated in workflow #235 for commit fbdd583 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an “AUTH-4” re-authentication signal to help migrate/reauth clients consistently across HTTP and websockets, and strengthens v2 token verification by explicitly detecting revoked/expired session rows (instead of filtering them out at query time).

Changes:

  • Add AuthService.authenticate() returning a richer AuthResult (actor/reauth/invalid) and emit reauth reasons for revoked/expired sessions and legacy-v1 tokens.
  • Update HTTP auth probe + gates and socket.io auth middleware to propagate reauth_required to clients (including structured payloads) and add KV/log-based observability.
  • Extend SessionStore with a raw session lookup path to support revocation/expiry classification, and add/extend unit + integration tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/backend/stores/session/SessionStore.js Split “active-only” session lookup from a raw lookup to support revoked/expired classification.
src/backend/services/socket/SocketService.ts Add socket-side reauth error payload + decision helper and switch socket auth to AuthService.authenticate().
src/backend/services/socket/SocketService.test.ts Unit tests for socket reauth error packing and auth decision logic.
src/backend/services/auth/AuthService.ts Introduce AuthResult / ReauthReason, add authenticate(), and emit reauth for revoked/expired/legacy scenarios.
src/backend/services/auth/AuthService.test.ts Integration tests for the new authenticate() result shape and reauth reasons.
src/backend/server.ts Wire the server KV store into the global auth probe for metrics.
src/backend/core/http/middleware/gates.ts Gate now returns reauth_required when the probe marks requiresReauth.
src/backend/core/http/middleware/gates.test.ts Coverage for reauth-required gate behavior and precedence rules.
src/backend/core/http/middleware/authProbe.ts Probe now consumes authenticate() and sets requiresReauth, metrics, and logs.
src/backend/core/http/middleware/authProbe.test.ts Unit tests for reauth propagation, KV increments, and logging behavior.
src/backend/core/http/expressAugmentation.ts Extend Express.Request typing with requiresReauth.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* or leaves `req.actor` undefined for per-route gates to reject.
*/
async authenticateFromToken(token: string): Promise<Actor | null> {
const result = await this.authenticate(token);
Comment on lines 439 to 444
this.clients.event.emit(
`sent-to-user.${wireName}`,
{
user_id: userId,
user_id: userId as number,
response: data.response,
},
Comment on lines +37 to +40
type AuthResultLike =
| { actor: Actor }
| { reauth: { reason: string; auth_id?: string } }
| { invalid: true };
Comment on lines +79 to 84
async getByUuidAny(uuid) {
if (!uuid) return null;

const now = nowSeconds();
const cached = await this.#readCache(uuid);
if (cached) {
if (cached.revoked_at != null) return null;
if (isExpired(cached, now)) return null;
return cached;
}
if (cached) return cached;

@Salazareo Salazareo merged commit 5394ccc into main May 26, 2026
5 checks passed
@Salazareo Salazareo deleted the DS/put-1015 branch May 27, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants