Skip to content

fix(store): write the session file with 0600 like the rest of the store - #32

Open
leemour wants to merge 1 commit into
dapi:mainfrom
leemour:fix/session-file-permissions
Open

leemour wants to merge 1 commit into
dapi:mainfrom
leemour:fix/session-file-permissions

Conversation

@leemour

@leemour leemour commented Sep 11, 2026

Copy link
Copy Markdown

What

session.json is the only credential file in the store left at the process umask — on a default umask it is created 0644. Everything else the store writes is explicit: config.json, account.json and the account registry are 0600, and their directories are 0700 (core/accounts.js).

The difference exists because mtcute writes the session file, not tgcli, so the store's own mode discipline never reaches it. This applies a chmod after a successful login, where the file is known to exist.

Severity: consistency, not a live hole

Worth being precise, since a permissions patch invites the wrong reading. Nothing is exposed today — the enclosing directories are 0700, so the file mode is never what stands between the auth key and another user.

It matters where the directory mode stops carrying the guarantee: a store placed on a shared or synced volume, a backup or archive that preserves file modes but recreates directories, or an environment with a relaxed umask. In those cases the file mode is the only thing left, and right now it is 0644.

Details

  • Runs on the success path of login(), so it also repairs stores created by earlier versions.
  • A missing or foreign-owned session file is ignored rather than failing the login.
  • npx vitest run — 299 passed, 1 skipped, 19 files. Two new tests: narrowing a 0644 file, and not throwing when the file is absent.

Split out from #31 as suggested there; the two changes are unrelated.

The store deliberately creates config.json, account.json and the account
registry with mode 0600 and their directories with 0700. session.json is the
one credential file left at the process umask, because mtcute writes it — so
on a default umask it lands as 0644.

The enclosing directories are 0700, so nothing is exposed today; this is
consistency rather than a live hole. It matters for the cases that reach past
the directory mode: a store on a shared or copied volume, a backup that
preserves file modes but not directory ones, or a umask-relaxed environment.

Applied after a successful login, where the file is known to exist. A missing
or foreign-owned file is ignored rather than failing the login.
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