mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 15:42:01 +03:00
harden safe_name path validation
This commit is contained in:
parent
1a12d75ec6
commit
a6fc5b90f3
1 changed files with 12 additions and 1 deletions
|
|
@ -35,7 +35,18 @@ fn docs_dir(app: &AppHandle, dir: &Option<String>) -> PathBuf {
|
|||
}
|
||||
|
||||
fn safe_name(name: &str) -> bool {
|
||||
!name.is_empty() && !name.contains(['/', '\\', ':']) && !name.contains("..")
|
||||
let path = Path::new(name);
|
||||
let mut components = path.components();
|
||||
match components.next() {
|
||||
Some(std::path::Component::Normal(_)) => {
|
||||
if components.next().is_none() {
|
||||
!name.contains(['/', '\\', ':'])
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue