fix(native): create TLS private keys at mode 0600, not chmod after write - #6353
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(native): create TLS private keys at mode 0600, not chmod after write#6353pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug, found while auditing
apps/nativerelease/updater code.local_tls::write_privateis the only place the per-machine CA root key and the per-launch leaf key ever hit disk. It wrote the key bytes withfs::write(which creates the file at the process's default, umask-derived mode — typically0644), then calledfs::set_permissionsto tighten it to0600in a second syscall. Between those two steps the key sat world/group-readable.The file's own module doc calls out exactly this threat model: "a stolen
ca-key.pem— readable by any process running as this user, including code the app itself runs in sandboxes — would be a general-purpose authority for every TLS connection this user makes." The write-then-chmod ordering left a real (if narrow) window for that.Fix: open the file with
OpenOptionsExt::mode(0o600)so it's created at0600from the first syscall — no window. Also re-asserts the mode after open (viaset_permissions) to handle the case where a key file predating this fix already exists on disk with looser permissions from a prior run.Verification: added two unit tests —
write_private_creates_the_file_mode_0600(new file lands at exactly0600) andwrite_private_tightens_a_pre_existing_looser_file(a pre-existing0644file gets tightened and its contents replaced). Both pass:(Needed a placeholder
binaries/rclone-<target>file locally to satisfybuild.rs's sidecar-binary check — that's an unrelated pre-existing dev-setup requirement, not part of this diff.)Ran
cargo fmt -- --check src/local_tls.rs(clean).cargo clippyisn't installed in this sandbox's toolchain; CI's rust-checks job covers it.Only
apps/native/src-tauri/src/local_tls.rsis touched — one file, one concern, +56/-9.Summary by cubic
Writes TLS private keys with mode 0600 at creation on Unix, removing the write-then-chmod window that briefly exposed keys at umask-derived perms (typically 0644). New behavior opens the file with
OpenOptionsExt::mode(0o600)and also re-asserts 0600 after open to tighten pre-existing files when rewritten.apps/native/src-tauri/src/local_tls.rsonly; behavior change is Unix-only. Non-Unix still uses the existing write path.ca-key.pemor leaf keys group/world-readable between syscalls.chmod 600or rotate the key; future writes will auto-tighten.Written for commit 259a21f. Summary will update on new commits.