fix(cli): export --account writes the .mac file with 0600 permissions - #2469
Open
ygd58 wants to merge 1 commit into
Open
fix(cli): export --account writes the .mac file with 0600 permissions#2469ygd58 wants to merge 1 commit into
ygd58 wants to merge 1 commit into
Conversation
export_account writes AccountFile (whose auth_secret_keys field carries the account's raw secret keys) to disk via plain File::create(), which on Unix creates the file with the process's default umask permissions (typically 0644 - world-readable). Any local user on a shared machine could read another user's exported account secret keys from this file. 0xMiden#1833 (merged) already audited and fixed this exact class of issue for the filesystem keystore (crates/rust-client/src/keystore/fs_keystore.rs) and the SQLite database (crates/sqlite-store/src/db_management/ pool_manager.rs), but didn't cover this CLI export command, which writes the same kind of secret key material to an arbitrary, user-chosen path. Adds two small helpers mirroring the fix already applied to fs_keystore.rs: create_secret_data_file opens with OpenOptions::mode( 0o600) on Unix so the file is 0600 from creation, and restrict_secret_data_file_permissions calls set_permissions(0o600) explicitly afterwards, since OpenOptions::mode only applies when a file is newly created - it has no effect if a file already existed at that path (e.g. a stale export left over from a previous run) and is truncated and reopened for writing instead. export_note (which writes public note data, not secret keys) is left unchanged. Adds two unit tests on the helpers directly, without needing the full async Client/keystore setup export_account itself requires: one asserting a freshly created file is 0600, one asserting a pre-existing 0644 file still ends up 0600 after being overwritten. I don't have a matching Rust toolchain in my current environment, so this needs local build + test verification before being considered ready, same as my prior PRs in this repo.
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.
export_accountwritesAccountFile(whoseauth_secret_keysfield carries the account's raw secret keys) to disk via plainFile::create(), which on Unix creates the file with the process's default umask permissions (typically0644- world-readable). Any local user on a shared machine could read another user's exported account secret keys from this file.Context
#1833 (merged) already audited and fixed this exact class of issue for the filesystem keystore (
crates/rust-client/src/keystore/fs_keystore.rs) and the SQLite database (crates/sqlite-store/src/db_management/pool_manager.rs), but didn't cover this CLI export command, which writes the same kind of secret key material to an arbitrary, user-chosen path.Fix
Adds two small helpers mirroring the fix already applied to
fs_keystore.rs(see #2468):create_secret_data_fileopens withOpenOptions::mode(0o600)on Unix so the file is0600from creation, andrestrict_secret_data_file_permissionscallsset_permissions(0o600)explicitly afterwards, sinceOpenOptions::modeonly applies when a file is newly created - it has no effect if a file already existed at that path (e.g. a stale export left over from a previous run) and is truncated and reopened for writing instead.export_note(which writes public note data, not secret keys) is left unchanged.Test plan
Added two unit tests on the helpers directly, without needing the full async
Client/keystore setupexport_accountitself requires: one asserting a freshly created file is0600, one asserting a pre-existing0644file still ends up0600after being overwritten.Ran locally, not just CI:
Both new tests:
ok. Full lib suite:8 passed, 0 failed- no regressions.