Repository navigation
Reject sessions issued before a password change - #301
Conversation
BaaRai
left a comment
There was a problem hiding this comment.
Thanks for taking on session revocation, it is the right fix for a compromise scenario. The epoch check in verifyJWT is right (server/auth.go:186). In the four cases below, sessions that a password change should revoke keep working.
1. reset-password.sh does not write the epoch. The script only upserts auth.password_hash (reset-password.sh:143-150), then says no restart is needed (reset-password.sh:239). Sessions issued before an emergency reset stay valid. The running server would not see a new epoch anyway, because loadPwdEpoch reads it only at startup (server/auth.go:309-327).
Fix: have the script write auth.password_epoch in the same SQL, and either reload the epoch at runtime or tell the operator to restart.
2. Same-second gap. The epoch is stored in whole seconds (server/auth.go:336) and a token is rejected only when IssuedAt < notBefore (server/auth.go:186). A token issued earlier in the same second as the change still passes, as the comment at server/auth.go:329-330 admits.
Fix: use a cutoff that cannot tie, for example a password version claim in the token compared with a stored counter, or a finer-grained timestamp.
3. Both the write and the read fail open.
- Write: if
SetSetting(authPwdEpochKey, ...)fails,bumpPwdEpochonly logs and returns without updating the in-memory epoch (server/auth.go:337-340), and the handler still answers 200{"ok":true}(server/auth.go:466-467). - Read: any
GetSettingerror inloadPwdEpochis logged and returns (server/auth.go:313-316). The cutoff stays at 0, which accepts every valid token, for the whole life of the process.initSetupTokenretries 3 times (server/auth.go:278-291); the epoch read does not retry.
Fix: write the hash and the epoch in one transaction and return 500 on failure. At startup, retry the read, then refuse to start or reject tokens until the epoch is known.
4. Open SSE streams survive the change. The token is checked once, when the request enters requireAuth (server/auth.go:244). For example, streamLogs and streamActivity then loop until the client disconnects (server/server.go:3185-3202 and 3280 onward), so a stream opened with a revoked token keeps receiving data.
Fix: close the streams on a password change, or document that revocation applies to new requests only. Re-checking the token on each ping is another option.
Please add handler-level tests: change the password with token A, then A gets 401 on requireAuth and a fresh login passes; plus one test per failure path in point 3.
BaaRai
left a comment
There was a problem hiding this comment.
Thanks, this is the right shape: a monotonic version in the same transaction as the hash, reset-password.sh writing it and asking for a restart, and the three streams re-checking the token.
One gap remains: loadPasswordVersion runs only at startup. If that read still fails after the three attempts, pwdState stays unreadable for the life of the process: requireAuth rejects every session, login answers 503, and nothing ever re-reads the version. The instance is locked until a restart, and the CHANGELOG sentence "until a read succeeds" is not true today. Please either retry the read on login when the state is unreadable (fail closed, but self-heal when the database comes back), or change the sentence to "until the process restarts".
BaaRai
left a comment
There was a problem hiding this comment.
Thanks, the retry on login is the self-heal path: a failed startup read no longer locks the instance until a restart, and the wording now matches what the code does. Approved.
A failed password read no longer mints a setup token, and filling the login limiter no longer drops an active lockout.
…ne second. The hash and version commit together, a failed read rejects tokens, and the reset script tells the operator to restart.
bab334e to
134562c
Compare
…tter/session-epoch # Conflicts: # CHANGELOG.md
|
Let me know if this is good to merge. |
Summary
auth.password_epochis rejected. A deployment that has never stored an epoch still accepts existing tokens.Test plan