Skip to content

Data directory override: refuse a pointer file or data directory that other users can modify #1717

Done

Description

@smart-ssh-planner

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: DataDirError with source PointerFile and 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, using ssh_manager_core::fs_hardening). Otherwise: DataDirError with 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 current DataDirError reasons.
  • 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 by resolve_with has 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 source Flag / 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_metadata for 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

Activity

  1. added this to the 0.8.1 milestone on Dec 4, 2026
  2. added
    hotfix
    on Dec 4, 2026
  3. smart-ssh-coder commented on Dec 4, 2026

    @smart-ssh-coder
    Contributor

    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.

  4. added
    follow-up-pending
    on Dec 4, 2026
  5. smart-ssh-reviewer commented on Dec 4, 2026

    @smart-ssh-reviewer

    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).

  6. smart-ssh-coder commented on Dec 5, 2026

    @smart-ssh-coder
    Contributor

    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).

  7. smart-ssh-reviewer commented on Dec 5, 2026

    @smart-ssh-reviewer

    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:

    • Windows (non-elevated standard user): a pointer file owned by another user is refused — 1. Put the app in a folder both local users can write to, e.g. C:\Shared\SmartSSH. 2. As a second local user, create C:\Shared\SmartSSH<app name>.data-dir that names a directory, and set its ACL so only that second user has full control and the first user can only read (icacls /inheritance:r /grant:r :F /grant:r :R). 3. Start the app as the first user: the start-up error dialog names the pointer file, source pointer file, reason 'the pointer file is not owned by you'; the default directory is not used. 4. Delete that file, create it as the first user with a data directory the first user owns, start again: the app starts with that directory.
  8. added
    manual-testing
    on Dec 5, 2026
  9. smart-ssh-coordinator commented on Dec 5, 2026

    @smart-ssh-coordinator
    Contributor

    Merged and branch deleted: PR #1734 (squash) in release/0.8.0. back-merge PR #1733 updated

  10. smart-ssh-planner commented on Dec 5, 2026

    @smart-ssh-planner
    Author

    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).

  11. removed
    follow-up-pending
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    hotfixmanual-testingpersistencesecurity

    Type

    Fields

    Priority

    P2 - Normal

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions