Repository navigation
Description
Goal
A data directory override only takes effect when the pointer file and the data directory it names cannot be modified by other local users. Otherwise the app stops at start-up with a clear message, as it already does for an unusable override, instead of running with files that another account can plant or change.
Context
Spec 0115: the data directory can be overridden by --data-dir, SMART_SSH_DATA_DIR, or a pointer file next to the app (<app name>.data-dir; pointer_file_path, crates/persistence-sqlite/src/paths.rs:162-199). resolve_with (crates/persistence-sqlite/src/paths.rs:274-324) reads the pointer file, resolves the target (pointer_file_target, select_override), creates the directory and only checks that it is a directory and not read-only. Neither the owner of the pointer file nor the owner and permissions of the target directory are checked.
Everything of that instance lives in the data directory: the database, host_keys.json, settings.json, the key wrapping file in master password mode, logs and speech models (Spec 0115, THREAT-MODEL.md section 3). If the app sits in a folder other accounts can write to (a portable copy in a shared folder, a folder directly under C:\ with default permissions, an AppImage in a shared directory), another account can place or replace the pointer file and point the instance at a directory it controls and has pre-filled. --data-dir and the environment variable come from the user's own invocation and are not affected.
An unusable override already stops the start with an error dialog naming the path, the source and the reason, never falling back to the default directory (DataDirError, crates/app-shell/src/startup_dialog.rs:259).
Requirements
- Pointer file (only when the override comes from the pointer file): on Unix it must be owned by the current user or by root and must not be group- or world-writable; on Windows its DACL must not grant write, modify, delete or ownership rights to broad groups (Everyone, Authenticated Users, BUILTIN\Users, Guests, Anonymous). Otherwise:
DataDirErrorwith sourcePointerFileand a reason such as "the pointer file can be modified by other users". - Data directory (for every override source: flag, environment, pointer file): if it exists, on Unix it must be owned by the current user and must not be world-writable; on Windows the same DACL rule as above. A directory the app creates itself is created owner-only (Unix
0700, usingssh_manager_core::fs_hardening). Otherwise:DataDirErrorwith a reason such as "the data directory is not owned by you" / "the data directory can be modified by other users". - A group-writable data directory on Unix that is owned by the current user is accepted (common with per-user groups and umask 002) and logged once as a warning after logging starts.
- The default data directory (no override) is not checked; nothing changes there.
- The checks run in
resolve_with, so the existing start-up error dialog shows them; no new dialog. Texts in the existing locales next to the currentDataDirErrorreasons. - THREAT-MODEL.md section 3 and Spec 0115: state the ownership rule.
Acceptance Criteria
- Unix tests (
crates/persistence-sqlite, temp dirs): a world-writable pointer file → error; a group-writable pointer file → error; a pointer file owned by the current user with mode 0644 → accepted; a world-writable target directory → error; an existing target owned by the user with 0700 or 0770 → accepted; a target created byresolve_withhas mode 0700. - Test with a pure function for the decision (owner, mode, current uid → allowed or reason), so that "owned by another user" and "owned by root" are covered without root rights.
- Windows test (
#[cfg(windows)]): a directory whose DACL grants Everyone write access → error; a directory with default per-user permissions under the temp directory → accepted. -
--data-dir/ environment override pointing to a world-writable directory → error with sourceFlag/Env. - No override → default directory, no new checks, existing tests unchanged.
- Relevant automated tests pass.
Technical Notes
- Security-relevant area (where the database and key material are loaded from). The check must not fall back to the default directory on failure; Spec 0115 already forbids that.
- Use the file's own metadata (
symlink_metadatafor the pointer file: a symlinked pointer file counts as not trusted unless the link and its target pass the same check; the simplest correct rule is to refuse a symlink). - Windows:
GetNamedSecurityInfoW+ walking the DACL (windows-sys); keep it in a small#[cfg(windows)]module. - No data model change.
Files: crates/persistence-sqlite/src/paths.rs, crates/persistence-sqlite/src/ (new module for the ownership check and its tests), crates/persistence-sqlite/Cargo.toml, crates/app-shell/src/startup_dialog.rs, frontend locales for the new reasons, THREAT-MODEL.md, docs/specs/0115-datenverzeichnis-override.md
Spec impact: update 0115
Open questions
- Where the localized reason texts live today for
DataDirError(backend string vs. frontend locale key): follow the existing pattern.
Related Work
- Data directory override: --data-dir flag and a pointer file next to the app, and every app file follows it #1313 (data directory override), Data directory override: pointer file with ~ and unknown home must be a start-up error, not the default directory #1322 (pointer file with
~) - Integrity of local data at rest against modification without the database key #1720 (epic: integrity of local data at rest)
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix(persistence-sqlite): refuse data dir overrides other users can mo…
fix(persistence-sqlite): gate Unix-only reason constants (#1717)
test(persistence-sqlite): drop unused imports on Windows (#1717)
test(persistence-sqlite): fix imports of the Unix data dir tests (#1717)
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1734. Data directory overrides are now refused when the pointer file or data directory can be modified by other users (Unix owner/mode checks, Windows DACL check, 0700 for self-created dirs, group-writable warning). Spec 0115, threat model and changelog updated; Unix unit tests with counter-proof; CI green on all platforms including Windows.
smart-ssh-reviewer commentedon Dec 4, 2026
Review: 1. Windows has no owner check (data_dir_trust.rs:191-220): another user can create the pointer file in a shared app folder, own it, give it a narrow DACL without broad SIDs and redirect the instance. Also request OWNER_SECURITY_INFORMATION; the owner must be the current token user (pointer file: also Administrators/SYSTEM/TrustedInstaller); pure decision function plus a #[cfg(windows)] test. 2. Allow ACEs other than type 0 are skipped (data_dir_trust.rs:263): evaluate callback ACEs (type 9) too; parse object ACEs (5, 11) correctly or refuse them when they carry modifying rights. 3. A FIFO as the pointer file hangs start-up (data_dir_trust.rs:82-89): refuse anything that is not a regular file before opening, open with O_NONBLOCK|O_NOFOLLOW on Unix, add a mkfifo test. 4. Spec 0115 §4.1 and THREAT-MODEL.md claim a created directory is 0700 on every platform and that only existing directories are checked: limit 0700 to Linux/macOS and state that a newly created directory is checked too (on Windows it inherits the parent's ACL). 5. Fix the comments that contradict the code: data_dir_trust.rs:72-74 (Windows reads the DACL by path), :254-255 (mask is read before the type check), :190 ({what} also for the pointer file), :6-7 (group-writable is accepted), paths.rs:317 (only the leaf gets 0700).
fix(persistence-sqlite): check owner and all allow ACEs on Windows, r…
fix(persistence-sqlite): accept Administrators-owned data dirs on Win…
smart-ssh-coder commentedon Dec 5, 2026
Implementation ready for review. PR #1734. All five review points fixed: Windows owner check, callback/object ACE evaluation, FIFO pointer file refused without blocking (O_NONBLOCK|O_NOFOLLOW), spec/threat-model wording, comments. Linux tests incl. FIFO pass; CI green (Windows logic covered by CI).
smart-ssh-reviewer commentedon Dec 5, 2026
Review passed – moving on to merge. All five findings from the last review are fixed. On Windows the pointer file and data directory are now checked for their owner, callback and object ACEs are evaluated, and a FIFO or other non-regular pointer file is refused without blocking. The spec and threat-model wording and the comments now match the code. CI is green on all platforms, and the local Linux tests, clippy and fmt pass, including a counter-proof for the FIFO test. Non-blocking: on Windows an Administrators-owned data directory is accepted without a membership check (not a loosening; an ADR is recommended), small spec wording points, and a stale PR body. Follow-ups (label follow-up-pending): read owner/DACL from the opened handle on Windows, a Windows test with a real foreign owner SID, an ADR for the open calls, and the items carried over from the last review.
Manual testing after the merge:
fix(persistence-sqlite): refuse data dir overrides other users can mo…
smart-ssh-coordinator commentedon Dec 5, 2026
Merged and branch deleted: PR #1734 (squash) in release/0.8.0. back-merge PR #1733 updated
smart-ssh-planner commentedon Dec 5, 2026
Follow-ups filed: #1748 Windows trust check: read owner/DACL from the opened handle, full SID bounds check, test with a real foreign owner SID; #1749 ADR for the open decisions of the data directory trust check; #1750 refuse a parent directory chain that other users can modify (Unix); #1751 Windows: owner-only DACL for the created data directory and more broad SIDs. Not filed (style/taste, no user impact): FAT/exFAT notice, code-shape cleanups (shared sid_eq, current_uid, message templates, strict create helper).