From ae9b415a75d74734b2dc66ef709732cf9727f2ed Mon Sep 17 00:00:00 2001 From: Cylae <13425054+Cylae@users.noreply.github.com> Date: Wed, 9 Sep 2026 00:58:06 +0000 Subject: [PATCH] fix(core): integrate validate_safe_path in core path operations Integrate validate_safe_path into core filesystem and locking operations (atomic_write, ProcessLock::acquire, Journal::open_or_create) to prevent path traversal attacks. --- server_manager/src/core/atomic_io.rs | 1 + server_manager/src/core/journal.rs | 1 + server_manager/src/core/lock.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/server_manager/src/core/atomic_io.rs b/server_manager/src/core/atomic_io.rs index 07e2030..a4c72da 100644 --- a/server_manager/src/core/atomic_io.rs +++ b/server_manager/src/core/atomic_io.rs @@ -15,6 +15,7 @@ use std::os::unix::fs::OpenOptionsExt; /// 4. Synchronizes to disk via `fsync` (`sync_all`). /// 5. Atomically renames the temporary file to the destination path. pub fn atomic_write>(path: P, content: &[u8], mode: u32) -> Result<()> { + crate::core::validate::validate_safe_path(path.as_ref())?; let dest = path.as_ref(); let parent = dest.parent().unwrap_or_else(|| Path::new(".")); if !parent.as_os_str().is_empty() { diff --git a/server_manager/src/core/journal.rs b/server_manager/src/core/journal.rs index e4adc45..9b8246e 100644 --- a/server_manager/src/core/journal.rs +++ b/server_manager/src/core/journal.rs @@ -66,6 +66,7 @@ impl Journal { /// Opens or creates the journal file with 0600 permissions. pub fn open_or_create>(path: P) -> Result { + crate::core::validate::validate_safe_path(path.as_ref())?; let target = path.as_ref(); let parent = target.parent().unwrap_or_else(|| Path::new(".")); if !parent.as_os_str().is_empty() { diff --git a/server_manager/src/core/lock.rs b/server_manager/src/core/lock.rs index fb3e8cd..b578d18 100644 --- a/server_manager/src/core/lock.rs +++ b/server_manager/src/core/lock.rs @@ -15,6 +15,7 @@ impl ProcessLock { /// Attempts to acquire an exclusive lock on the specified path. /// If `non_blocking` is true and the lock is already held, returns an error immediately. pub fn acquire>(path: P, non_blocking: bool) -> Result { + crate::core::validate::validate_safe_path(path.as_ref())?; let target = path.as_ref(); let parent = target.parent().unwrap_or_else(|| Path::new(".")); if !parent.as_os_str().is_empty() {