fix(instance): reject unsafe instance rename targets
rename() now runs validate_name on the new name so paths like ../x or .x cannot move instances out of (or hide them inside) the instances root; failures surface as an error toast in the TUI.
This commit is contained in:
1 parent
40db30ce5a
commit
51bb896f91
2 files changed
+21
No files matched your search
@@ -1,3 +1,6 @@
|
||||
// SPDX-FileCopyrightText: 2026 Constantin Bauer
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use super::*;
|
||||
use crate::instance::models::ModLoader;
|
||||
use tempfile::TempDir;
|
||||
@@ -129,6 +132,17 @@ fn rename_empty_target_rejects() {
|
||||
assert!(matches!(err, InstanceError::InvalidName(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_traversal_target_rejects() {
|
||||
let (manager, tmp) = test_manager();
|
||||
std::fs::create_dir_all(tmp.path().join("orig")).unwrap();
|
||||
manager.save(&dummy_config("orig")).expect("save");
|
||||
let err = manager.rename("orig", "../escape").unwrap_err();
|
||||
assert!(matches!(err, InstanceError::InvalidName(_)));
|
||||
assert!(!tmp.path().parent().unwrap().join("escape").exists());
|
||||
assert!(tmp.path().join("orig").exists(), "source must be untouched");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rename_missing_source_errors() {
|
||||
let (manager, _tmp) = test_manager();
|
||||
|
||||
Reference in new issue
Block a user