Skip to content

Commit 892b0ea

Browse files
committed
ensure data directories have appropriate permissions
1 parent e44282e commit 892b0ea

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

src-tauri/src/bin/defguard-client.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
44
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
55

6-
use std::{env, str::FromStr, sync::LazyLock};
6+
use std::{
7+
env,
8+
fs::{set_permissions, Permissions},
9+
os::unix::fs::PermissionsExt,
10+
str::FromStr,
11+
sync::LazyLock,
12+
};
713

814
#[cfg(target_os = "windows")]
915
use defguard_client::utils::sync_connections;
@@ -277,15 +283,22 @@ fn main() {
277283
app.run(|app_handle, event| match event {
278284
// Startup tasks
279285
RunEvent::Ready => {
286+
// Ensure data directory has appropriate permissions (dg25-28)
287+
let data_dir = app_handle
288+
.path()
289+
.app_data_dir()
290+
.unwrap_or_else(|_| "UNDEFINED DATA DIRECTORY".into());
291+
if let Err(err) = set_permissions(&data_dir, Permissions::from_mode(0o700)) {
292+
warn!(
293+
"Failed to set permissions on data directory {}: {err}",
294+
data_dir.display()
295+
);
296+
}
280297
info!(
281298
"Application data (database file) will be stored in: {} and application logs in: {}. \
282299
Logs of the background Defguard service responsible for managing VPN connections at the \
283300
network level will be stored in: {}.",
284-
// display the path to the app data directory, convert option<pathbuf> to option<&str>
285-
app_handle
286-
.path()
287-
.app_data_dir()
288-
.unwrap_or_else(|_| "UNDEFINED DATA DIRECTORY".into()).display(),
301+
data_dir.display(),
289302
app_handle
290303
.path()
291304
.app_log_dir()

0 commit comments

Comments
 (0)