Repository navigation
feat(session): externalizable ISessionStore, /api/me/sessions API & active sessions UI (P2-3) - #389
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
98cf836 to
1db86a3
Compare
voidvec
left a comment
There was a problem hiding this comment.
Review: P2-3a session store / /api/me/sessions / active-sessions UI
Reviewed at 1db86a3f against 31214d4b (47 files, +5364/-45). All required checks are green (gcov GATE + TSan nightly are skipped by design). The overall shape is good: port in identity, Drogon adapter in drogon, controller wiring behind filters, register-time revocation on /oauth2/authorize, OpenAPI/route-manifest/api-baseline/SDK regenerated, no new error codes. Findings below are ordered by severity.
BLOCKING
1. GET /api/me/sessions returns the raw Drogon session id (the JSESSIONID cookie value).
libs/drogon/src/controllers/UserSelfServiceController.cc (item["session_id"] = rec.sessionId) and SessionStoreHelper::recordAuthenticatedSession (record.sessionId = req->session()->sessionId()) mean the API hands out a live credential, not an identifier. The new test proves it: tests/integration/endpoints/SessionGovernanceHttpTest.cc matches item["session_id"] against sessionB->sessionCookie literally.
Impact: anyone holding a Bearer token for the user (stolen access token, XSS on the SPA reading the response, logs/replay tooling) can set Cookie: JSESSIONID=<sid> and become that browser session — then hit /oauth2/authorize?prompt=none and mint codes/tokens without password or MFA. That converts a short-lived token compromise into a persistent SSO-session compromise, which is the exact capability this feature is supposed to let users kill.
Fix: expose an opaque per-session handle instead of the cookie value — e.g. store a random publicId in SessionRecord (persisted next to sessionId) and return it; resolve publicId -> sessionId server-side inside revokeSession/listByUser comparisons for is_current. Update OpenAPI/UserSession description accordingly and extend the test to assert session_id != sessionCookie.
2. touch() is never called from production code, so tracked sessions hard-expire session_timeout after login.
Grep over the PR: touch is invoked only by RedisSessionStoreTest/MemorySessionStoreTest. recordAuthenticatedSession writes the record once (login / MFA elevation / WebAuthn) and nothing refreshes it. Drogon's CacheMap slides on every access, but the store record keeps expiresAt = login + ttl.
Combined with AuthorizationEndpointController's eviction branch (NotFound && tracked_in_store -> session()->clear()), an actively used session is force-logged-out at TTL: log in, keep browsing past session_timeout, next /oauth2/authorize reports login_required. That is a behavior regression versus the previous sliding-expiry semantics, and it is also why last_seen_at/expires_at in the UI are frozen at login time.
Fix: renew on activity (e.g. touch from the authorize success path with a throttle, or reuse the existing login-time write path on session-bearing requests), and add a test that a session survives past session_timeout while actively used. MemorySessionStore also needs its lazy-expiry path to honor the refreshed record.
Important
3. RedisSessionStore::touch is a resurrect-a-revoked-session race.
libs/drogon/src/adapters/RedisSessionStore.cc: touch does GET then SET %s %s EX %s with no condition. If revoke/revokeForUser (DEL) lands between the two round trips, the write recreates the key with a fresh TTL — a session the user just terminated comes back. Use SET ... XX EX (or a Lua script / WATCH) so a deleted key cannot be recreated, and add a test for touch-vs-revoke ordering. The integration test only asserts touch == Ok; it never reads the record back, so this slip is invisible.
4. Requested Redis backend silently degrades to MemorySessionStore.
apps/server/src/bootstrap/IdentityAssembly.cc: when storeBackend == "redis" but no "default" Redis client is configured, it logs LOG_WARN and continues with a process-local store. In a multi-replica deployment this is silently wrong: listByUser only sees sessions created on the current replica and revokeAllForUser cannot reach the other replicas — i.e. the security UI reports and enforces only a fraction of reality. Fail fast (refuse to start, or surface an explicit degraded mode in the API) when session.store=redis cannot be honored.
5. The knob is undocumented and the memory default hides the same multi-replica problem.
session.store / FULLA_SESSION_STORE appear nowhere in shipped configs, docs, or docker env files (grep across the tree finds only IdentityAssembly.cc). The default is memory, including for the postgres configs. Please document the knob (config reference + docker env example), and state the operator contract: memory backend is single-replica only; multi-replica deployments must set redis.
6. Every /oauth2/authorize now risks a 5 s stall when Redis degrades.
RedisSessionStore defaults timeoutSeconds = 5.0, and makeBoundedCallback only completes on timeout when the client buffers commands. The authorize path is the hottest login entry point; during a Redis outage each request can wait up to 5 s before falling back to the local session. Use a much shorter bound for the authorize lookup (sub-second) or prefetch asynchronously. Also note the consequence of Unavailable => dispatchLocalSession(): revocation is not enforced while Redis is unavailable — acceptable if documented, but it should be an explicit, documented trade-off rather than an implicit one.
7. MFA login silently skips session tracking on a parse failure.
libs/drogon/src/controllers/MfaController.cc: if std::stoi(sessUserId) throws (or sub is missing), recordAuthenticatedSession is skipped with an empty catch (...) and the flow continues. The session is then authenticated but untracked — invisible in /api/me/sessions, not evictable by revoke-all, and never evicted by the authorize NotFound branch (no tracked_in_store). Log it at minimum; better, treat it as an internal error for the verification response.
8. X-Forwarded-For is trusted unconditionally for the displayed IP.
SessionStoreHelper::extractSessionClientIp takes the first X-Forwarded-For entry, then X-Real-IP. A direct client (or a proxy that appends rather than sanitizes) fully controls what the session list shows as "where you are signed in". Gate XFF parsing on a trusted-proxy configuration (same list the rest of the deployment uses) and fall back to getPeerAddr() otherwise.
Minor
DELETE /api/me/sessions?exclude_current=truewith a Bearer-only caller (no cookie) yields an emptycurrentSid, sorevokeAllForUserreceives an emptyexceptSessionIdand revokes everything while the flag says "keep current". Either reject the flag without a session, or document that it only applies to cookie-bearing callers.RedisSessionStore::put(SET+SADD+EXPIRE, three round trips) can leave an orphaned index entry / an indexed-but-missing record on a crash. ThelistByUserpruning covers the read path; worth a comment or a small Lua script.revokeSessionechoessession_idback in the response body — fine once it becomes an opaque handle (see #1).
Verified good
- Port/adapter split keeps
identityfree of Drogon;MemorySessionStorecallback discipline (callbacks outside the mutex, owner-change onput) is correct. - Login revokes the pre-login session id and records the rotated id via the pending pre-sending-advice write; logout / OIDC end-session / forced-password-change all call
revokeRequestSession. - MFA-pending sessions are correctly not recorded at password stage (the MFA branch returns before
checkCodeIssuanceGuards), and MFA elevation/WebAuthn record withmfaPending=false, so the authorize path cannot be used to skip MFA. - No new error codes; the endpoint reuse of
AUTH_SESSION_REQUIRED/VALIDATION_*/INTERNAL_ERRORmeans the 8-point error-code sync list is untouched. Route manifest, OpenAPI (yaml + json) and api-baseline all carry the three new routes. - Frontend never renders
session_id; revoke-current and revoke-all both log out locally, and bulk buttons gate onhasOtherSessions.
Happy to re-review once #1 and #2 are addressed; the rest can reasonably become follow-ups if you prefer to land the feature in increments.
1db86a3 to
062dc0e
Compare
…sions governance API (P2-3a)
062dc0e to
cf344bc
Compare
Summary
n- **P2-3a Backend & SDK**:n - Add domain port `fulla::identity::ISessionStore` and default `MemorySessionStore` (zero Drogon deps)n - Add \RedisSessionStore` adapter and wire `session.store` / `FULLA_SESSION_STORE` in `IdentityAssembly` (staging rotated session writes via Drogon `PreSendingAdvice`)n - Integrate controllers and expose \GET /api/me/sessions`, `DELETE /api/me/sessions/{sessionId}`, `DELETE /api/me/sessions?exclude_current=true`n - Sync OpenAPI YAML/JSON, route manifests, API baseline, Python/Go/TS SDKs, and add unit + Redis + HTTP integration testsn- P2-3b User Security UI:n - Add \UserSession` type, `userService` session endpoints, and bilingual en/zh-CN i18n keysn - Add Active Sessions management card on \SecurityPage.vue` (list current/other devices, revoke single device, sign out other devices, sign out all devices)`n - Add Vitest unit tests and Playwright E2E coverage