Impersonation routes: missing auth checks on 3 endpoints + expiry bug #77
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
PR #75 (
feat/impersonation-backend) introduces impersonation session routes with security and logic issues found during QA review.Issues
1. Missing authorization on read/log endpoints (Security)
Affected endpoints:
GET /api/impersonation/sessions/:id(line 133) — no ownership checkGET /api/impersonation/sessions/:id/audit-log(line 254) — no ownership checkPOST /api/impersonation/sessions/:id/log(line 222) — no ownership checkImpact: Any authenticated user can read any impersonation session details, view its full audit trail, or inject arbitrary audit log entries — just by guessing/knowing a session UUID.
Expected behavior: These endpoints should verify
session.staffId === caller.staffId(or require manager role), matching the pattern already used in theextendandendendpoints.2. Extend allows extending expired sessions (Bug)
Reproduction:
expiresAt)expiresAtto pass (or simulate by setting a short timeout)POST /api/impersonation/sessions/:id/extendRoot cause:
expireTimedOutSessions()is only called during session creation (POST /sessions). Theextendendpoint checkssession.status !== "active"but the DB status is never updated to"expired"until someone creates a new session.Expected behavior: All session-specific endpoints should check
session.expiresAt <= nowbefore operating on the session.Related
All 3 issues reported here have been fixed in PR #75:
resolveStaff()+ ownership verification added toGET /sessions/:id,POST /sessions/:id/log, andGET /sessions/:id/audit-logcheckAndExpireSession()helper now called in extend, end, get, and log endpointsQA verified and approved. Keeping this issue open until PR #75 is merged per policy.
Both issues reported here have been fixed in PR #75:
resolveStaff()+session.staffId === staffRow.idcheckAndExpireSession()helper auto-expires timed-out sessions in DB, called inextend,end,GET /sessions/:id, andPOST /sessions/:id/log23 new tests cover all these scenarios. QA re-reviewed and approved. This issue will close when PR #75 merges.
Resolved in PR #75 (merged 2026-03-20). All 3 authorization checks and the expiry bug were fixed before merge — see QA re-review approval on the PR.