mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
Harden path sanitization in safe_name
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
f5b1fc038b
commit
e183f58af1
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