Skip to content

Commit 4ad1304

Browse files
authored
Merge pull request #741 from tnull/2026-01-stricter-seed-file-permissions
Set restrictive file permissions for seed file
2 parents 861f6e3 + e93844a commit 4ad1304

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/io/utils.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
use std::fs;
8+
use std::fs::{self, OpenOptions};
99
use std::io::Write;
1010
use std::ops::Deref;
1111
use std::path::Path;
1212
use std::sync::Arc;
1313

14+
#[cfg(unix)]
15+
use std::os::unix::fs::OpenOptionsExt;
16+
1417
use bdk_chain::indexer::keychain_txout::ChangeSet as BdkIndexerChangeSet;
1518
use bdk_chain::local_chain::ChangeSet as BdkLocalChainChangeSet;
1619
use bdk_chain::miniscript::{Descriptor, DescriptorPublicKey};
@@ -77,7 +80,11 @@ pub(crate) fn read_or_generate_seed_file(
7780
fs::create_dir_all(parent_dir)?;
7881
}
7982

80-
let mut f = fs::File::create(keys_seed_path)?;
83+
#[cfg(unix)]
84+
let mut f = OpenOptions::new().write(true).create_new(true).mode(0o400).open(keys_seed_path)?;
85+
86+
#[cfg(not(unix))]
87+
let mut f = OpenOptions::new().write(true).create_new(true).open(keys_seed_path)?;
8188

8289
f.write_all(&key)?;
8390

0 commit comments

Comments
 (0)