fix!: reject untrusted output symlinks and special files
In a world-writable sticky directory, a symlink could redirect a save onto an unrelated file. Saltybox accepts a link in such a directory only if it belongs to the running account or the directory owner. This applies to links in parent components and at the final name. Existing destinations must be regular files, which protects named pipes and devices from being replaced with plaintext or ciphertext.
update uses the same resolved directory and filename to read the encrypted file and save its replacement, so retargeting a path symlink cannot redirect the save. It checks that the filename still refers to the file it validated just before the rename. A concurrent replacement can still occur between that check and the rename.
The symlink resolver uses an API introduced in macOS 13, which is now the minimum supported version.
changelog: include
fix!: refuse untrusted output symlinks and non-regular outputs
saltybox followed output symlinks wherever they pointed. In a shared world-writable sticky directory such as /tmp, another local user could plant a symlink at the name the victim was about to write. saltybox resolved the link itself and renamed onto its target, so Linux's protected_symlinks restriction never applied. The result was that any file the victim can write could be overwritten with plaintext or ciphertext while the command exited 0. In a world-writable sticky directory, commands now refuse a symlink owned by neither the running account nor the directory owner. The rule covers links in directory components as well as the final name.
update also resolved the output path twice, once to read the existing file and once to replace it. A symlink retargeted during key derivation could make update validate the passphrase against one file and replace another, which SPEC.md says cannot happen. update now resolves the output once and reads and replaces through the same directory and name. Before renaming, it checks that the name still refers to the file it validated and aborts if it has changed. Another process can still replace that final filename between the check and the rename, so concurrent changes to a file while it is being updated remain unsupported.
An output path naming a named pipe or device was replaced with a regular file holding the output, so decrypt could leave plaintext where the user expected a stream or a device. An existing destination must now be a regular file. Directories, named pipes, devices, and other special entries are refused before anything is read or written.
This is a breaking change for macOS users. Reading a symlink target through an open descriptor needs an API introduced in macOS 13, so macOS 12 and earlier are no longer supported. Release binaries declare 13.0 as their minimum, and source builds on macOS should set MACOSX_DEPLOYMENT_TARGET=13.0.
changelog: include
fix!: harden output path resolution and require macOS 13
Following output symlinks without ownership checks allowed a symlink owned by another local account in a world-writable sticky directory to redirect saltybox's write onto any file writable by the caller, bypassing OS protected_symlinks protections because saltybox created a temporary file in the resolved directory and renamed it over the target. Separately, update resolved its output path more than once, so retargeting a symlink during passphrase entry or key derivation could validate one file and overwrite a different file. Naming a FIFO, device, or other special entry as -o also caused the rename to replace that entry with a regular file, which for decrypt could write plaintext to disk at a path intended as a pipe or device.
On Linux and macOS, saltybox now walks the output path once, component by component, holding open directory descriptors from resolution through temporary file creation, cleanup, rename, and directory sync. Any symlink inside a world-writable sticky directory owned by neither the running account nor the directory owner is rejected across both intermediate directory components and the final name, with symlink traversal bounded at 40 hops to catch cycles. Existing destinations must be regular files (directories, named pipes, devices, and other special entries are rejected before reading or writing), and commands recheck the resolved entry before creating the temporary file and again before renaming it. If temporary file cleanup fails after an error, saltybox queries the open directory descriptor for its current path and falls back to reporting the filename alongside the original path when the directory moved and cannot be resolved.
For update, saltybox opens the resolved encrypted file from that directory handle with no-follow and nonblocking flags and uses the open handle for input-alias detection. Moving an original symlink during prompting or validation cannot redirect the save. Immediately before rename, update verifies that the resolved name still refers to the validated file and aborts if a change is detected. Another process can still replace that final filename between the final check and rename, so concurrent modifications to the resolved file during update remain unsupported.
Reading ownership and target text from the same open symlink descriptor on macOS requires freadlink, introduced in macOS 13. Supported platforms are now Linux and macOS 13 or later, release builds set MACOSX_DEPLOYMENT_TARGET=13.0, and source builds on macOS should set MACOSX_DEPLOYMENT_TARGET=13.0 so the binary records that minimum OS version. On macOS, crate-level forbid(unsafe_code) is relaxed to deny(unsafe_code) solely for that single freadlink FFI call, with forbid(unsafe_code) retained on all other targets. Unsupported platforms keep the path-based write implementation.
changelog: include