Skip to main content

Module secure_io

Module secure_io 

Source
Expand description

User-only file helpers for secrets at rest.

On Unix, the helpers explicitly chmod the file/dir to 0o600 / 0o700 so other local users on the same machine cannot read them.

On Windows there is no chmod equivalent — the file inherits the ACL of its containing directory. We rely on Tauri placing our state inside %LOCALAPPDATA%\<identifier>\, which the OS already locks to the user’s SID via NTFS inheritance. The #[cfg(unix)] blocks below are therefore intentionally Windows no-ops, not missing coverage.

Functions§

ensure_user_only_dir
read_capped
Read a file, refusing to load more than max_bytes. Unbounded fs::read_to_string on attacker-controlled JSON is a denial-of- service primitive (a 4 GiB file gets loaded into RAM); every JSON state file we own should route through this. Returns ErrorKind::InvalidData when the file is too large so callers can distinguish from missing/permission errors.
spawn_periodic_dir_tighten
Spawn a detached background thread that re-runs tighten_existing_files_in_dir(&dir) every interval.
tighten_existing_file
tighten_existing_files_in_dir
tighten_once
One iteration of the periodic tighten sweep. Extracted from the spawn_periodic_dir_tighten loop so tests can drive a single tick synchronously instead of polling against a thread::sleep timer.
write_user_only