feat(web): persist session tokens across daemon restarts - #20
Merged
Conversation
SessionStore moves from auth.rs to sessions.rs. Tokens are now backed by ~/.nightcrow/sessions with owner-only permissions (0o600 on Unix via the platform::fs seam, no-op on Windows). Each token carries a 24h expiry matching the cookie Max-Age. Expired tokens are lazily removed on is_valid. Revoke wipes both memory and disk, so logout stays a real revocation. A corrupt or missing file starts an empty store instead of blocking startup. Closes code0xff#16
ViewerOptions carries a SessionStore instead of creating one inline. start_from_config loads from ~/.nightcrow/sessions, falling back to in-memory if the path is unavailable. Tests pass SessionStore::new() to stay isolated from disk.
architecture/web.md gains a session-persistence section and replaces the old 'no absolute TTL' residual risk with the persistence tradeoff (wider exposure window on non-loopback binds). web-viewer.md notes that sessions survive restarts and logout is server-side revocation.
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 #16.
What
Session tokens are now backed by
~/.nightcrow/sessionsso a browser thatwas logged in stays logged in after the daemon restarts. Previously every
restart invalidated all sessions because
SessionStorewas an in-memoryHashSetthat died with the process.Changes
src/platform/fs.rs— new platform seam:set_owner_only(Unix 0o600,Windows no-op + documented) and
write_atomic(temp file + rename).src/web/common/sessions.rs—SessionStoremoved out ofauth.rs,refactored from
HashSet<String>toHashMap<String, SystemTime>with:SESSION_TTL), matching the cookieMax-Age=86400.load(path)reads the file on startup, discarding already-expired tokens.issue()/revoke()persist to disk via atomic write.is_valid()lazily removes expired tokens.src/web/viewer/server/mod.rs—ViewerOptionscarries aSessionStore;start_from_configloads from~/.nightcrow/sessions,falling back to in-memory if the path is unavailable.
architecture/web.mdandweb-viewer.mdupdated with thepersistence model, TTL, and the disk tradeoff (wider exposure window on
non-loopback binds).
Security considerations
platform::fsseam. Windows hasno portable equivalent — documented as a no-op; operators should place the
state directory in an ACL-restricted location.
revokeremoves the token from bothmemory and disk, so clearing the cookie alone does not invalidate a session.
Secureflag (both recorded).On a non-loopback bind the token already crosses the network in plaintext;
persisting it widens the window from "until this process exits" to "until it
expires" — remote access should still use SSH tunnel or TLS reverse proxy.
Verification
cargo build(debug + release),cargo test(1550 pass),cargo clippy --all-targets --all-features -- -D warnings,cargo fmt --all --check— all green.