Skip to content

fix(auth): restore browser sessions only from a private session store - #32

Merged
akosidencio merged 1 commit into
devfrom
fix/auth-private-session-store
Nov 27, 2026
Merged

akosidencio merged 1 commit into
devfrom
fix/auth-private-session-store

Conversation

@akosidencio

Copy link
Copy Markdown
Member

Found in the v0.4.0 release-candidate review (model-based). The issue is pre-existing (M4-A).

Problem

attach_session_store read run/sessions-<port>.json with a plain File::open:

  • it followed symlinks and blocked on a FIFO;
  • it checked neither owner nor mode;
  • the private-directory rule existed only in write_private.

With a shared or pre-created TAILFLOW_DATA_DIR, another local user could create run/ and plant a fresh store holding a secret they know. The daemon loaded it, the rewrite then failed with only a warning, and the daemon accepted Cookie: tailflow_session_<port>=… with Sec-Fetch-Site: same-origin, a header any non-browser client can set. The default data directory (in the user's home) was not exposed.

Fix

On Unix, the store is read only when:

  • its directory and the file belong to the effective user with no group or other access (the same rule write_private enforces);
  • the file is a regular file, opened O_NOFOLLOW | O_NONBLOCK.

Otherwise the daemon logs a warning and restores no sessions, so the user signs in again. Windows behaviour is unchanged (per-user ACLs).

This adds the crate's only unsafe: libc::geteuid(), which has no preconditions and carries a SAFETY comment. libc was already a Unix dependency since #27.

Tests

  • New planted_session_stores_are_not_restored: shared directory, group/world-readable file, symlink and FIFO, with a private store as the control. With the privacy checks disabled it fails.
  • stale_session_stores_are_not_restored and expired_or_malformed_stored_sessions_are_dropped wrote stores by hand into tempfile directories, which are 0755. They now make them private, as the daemon does, so they keep testing age and validity rather than the new rule.
  • cargo test -p tailflow-daemon --bin tailflow-daemon auth::: 19 passed. Stable clippy is clean.

attach_session_store read run/sessions-<port>.json with a plain open: it
followed symlinks, blocked on a FIFO, and checked neither owner nor mode.
The private-directory rule existed only on the write side. With a shared
or pre-created TAILFLOW_DATA_DIR, another local user could create run/ and
plant a fresh store holding a secret they know. The daemon loaded it (the
rewrite then failed with only a warning) and accepted that session cookie.
The default data directory is in the user's home and was not exposed.

On Unix the store is now read only when its directory and the file belong
to this user with no group or other access, and the file is a regular file.
It is opened with O_NOFOLLOW | O_NONBLOCK. Anything else is ignored with a
warning: no sessions are restored and the user signs in again. Windows
keeps relying on the per-user ACLs of the data directory.

The two tests that write a store by hand now make it private, as the
daemon does (tempfile creates 0755 directories). A new test covers a
shared directory, a group/world-readable file, a symlink and a FIFO, with
a private store as the control. Found in the v0.4.0 release-candidate
review; pre-existing since M4-A.
@akosidencio
akosidencio merged commit da41591 into dev Nov 27, 2026
12 checks passed
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.

1 participant