Skip to content

Commit

Permalink
fix: fix check permission on temporary path
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-jerry committed Apr 30, 2024
1 parent 86d6706 commit 386aee0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
13 changes: 1 addition & 12 deletions core/tauri/src/api/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,7 @@ pub fn resolve_path<P: AsRef<Path>>(
BaseDirectory::App => app_config_dir(config),
#[allow(deprecated)]
BaseDirectory::Log => app_log_dir(config),
BaseDirectory::Temp => {
#[cfg(unix)]
{
// use real path on macos
// https://github.com/tauri-apps/tauri/issues/6256
Some(std::fs::canonicalize(temp_dir()).unwrap_or(temp_dir()))
}
#[cfg(not(unix))]
{
Some(temp_dir())
}
}
BaseDirectory::Temp => Some(temp_dir()),
BaseDirectory::AppConfig => app_config_dir(config),
BaseDirectory::AppData => app_data_dir(config),
BaseDirectory::AppLocalData => app_local_data_dir(config),
Expand Down
11 changes: 4 additions & 7 deletions core/tauri/src/scope/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,13 @@ mod tests {
fn check_temp_dir() {
use std::{
env::temp_dir,
fs::{canonicalize, remove_file, write},
fs::{remove_file, write},
};

let scope = new_scope();
let tmp_dir = canonicalize(temp_dir()).unwrap_or(temp_dir());
scope.allow_directory(tmp_dir.clone(), true).unwrap();
scope.allow_directory(temp_dir(), true).unwrap();

let test_temp_file = tmp_dir.clone().join("tauri_test_file");
let test_temp_file = temp_dir().join("tauri_test_file");
if test_temp_file.exists() {
remove_file(test_temp_file.clone()).unwrap();
}
Expand All @@ -418,9 +417,7 @@ mod tests {

write(test_temp_file.clone(), ".").unwrap();

let path = canonicalize(test_temp_file.clone()).unwrap();

assert!(scope.is_allowed(path));
assert!(scope.is_allowed(test_temp_file.clone()));

assert!(!scope.is_allowed("/var/**/file"));
assert!(!scope.is_allowed("/private/var/**/file"));
Expand Down

0 comments on commit 386aee0

Please sign in to comment.