Skip to content

Commit dbd9188

Browse files
author
Kevin Arthur
committed
fix(desktop): reject dot/dotdot lexically in resolve_user_path
On Windows, Path::exists() collapses a trailing 'Temp\X\..' to 'Temp' even when X doesn't exist, so the walk-up loop never saw the '..' component and traversal was silently accepted (the resolve_user_path_rejects_dotdot test failed on the windows-latest runner). Reject '.' and '..' components lexically before any syscall so behaviour is identical across platforms. Verified: all 7 resolve_user_path tests pass on Linux.
1 parent 6de4a1b commit dbd9188

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • apps/desktop/src-tauri/src

‎apps/desktop/src-tauri/src/lib.rs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,24 @@ fn resolve_user_path(raw: &str) -> Result<std::path::PathBuf, String> {
162162
let canonical = if path.exists() {
163163
std::fs::canonicalize(path).map_err(|e| format!("Failed to resolve path: {e}"))?
164164
} else {
165+
// Reject '.' / '..' components lexically, independent of the
166+
// filesystem. On Windows, Path::exists() collapses a trailing
167+
// `X\..` (Temp\X\.. resolves to Temp even when X doesn't exist),
168+
// so the walk-up loop below never observes the '..' component and
169+
// the traversal would be silently accepted. The lexical check runs
170+
// before any syscall so behaviour is identical across platforms.
171+
if path.components().any(|c| {
172+
matches!(
173+
c,
174+
std::path::Component::CurDir | std::path::Component::ParentDir
175+
)
176+
}) {
177+
return Err("Path must not contain '.' or '..' in a not-yet-existing segment".into());
178+
}
179+
165180
let mut ancestor = path;
166181
let mut suffix: Vec<&std::ffi::OsStr> = Vec::new();
167182
loop {
168-
if suffix
169-
.last()
170-
.is_some_and(|c| *c == "." || *c == "..")
171-
{
172-
return Err("Path must not contain '.' or '..' in a not-yet-existing segment".into());
173-
}
174183
if ancestor.exists() {
175184
break;
176185
}

0 commit comments

Comments
 (0)