Skip to content

feat(web): persist session tokens across daemon restarts - #20

Merged
whaclaw-bot merged 3 commits into
code0xff:devfrom
whackur:feat/persistent-sessions
Aug 4, 2026
Merged

feat(web): persist session tokens across daemon restarts#20
whaclaw-bot merged 3 commits into
code0xff:devfrom
whackur:feat/persistent-sessions

Conversation

@whaclaw-bot

Copy link
Copy Markdown
Collaborator

Closes #16.

What

Session tokens are now backed by ~/.nightcrow/sessions so a browser that
was logged in stays logged in after the daemon restarts. Previously every
restart invalidated all sessions because SessionStore was an in-memory
HashSet that 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.rsSessionStore moved out of auth.rs,
    refactored from HashSet<String> to HashMap<String, SystemTime> with:
    • 24h TTL (SESSION_TTL), matching the cookie Max-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.
    • Corrupt or missing file starts an empty store (never blocks startup).
  • src/web/viewer/server/mod.rsViewerOptions carries a
    SessionStore; start_from_config loads from ~/.nightcrow/sessions,
    falling back to in-memory if the path is unavailable.
  • Docsarchitecture/web.md and web-viewer.md updated with the
    persistence model, TTL, and the disk tradeoff (wider exposure window on
    non-loopback binds).

Security considerations

  • File permissions are 0o600 on Unix via the platform::fs seam. Windows has
    no portable equivalent — documented as a no-op; operators should place the
    state directory in an ACL-restricted location.
  • Logout remains a real revocation: revoke removes the token from both
    memory and disk, so clearing the cookie alone does not invalidate a session.
  • The viewer has no TLS and the cookie has no Secure flag (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.

whackur added 3 commits August 4, 2026 10:54
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.
@whaclaw-bot
whaclaw-bot merged commit 6a502d5 into code0xff:dev Aug 4, 2026
6 checks passed
@whaclaw-bot
whaclaw-bot deleted the feat/persistent-sessions branch August 4, 2026 02:10
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.

Web sessions should survive a daemon restart

2 participants