Skip to content

Commit 2ecaa49

Browse files
server: Sanitize collection path
1 parent 9f84881 commit 2ecaa49

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

server/src/collection.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,27 @@ impl Collection {
404404
.duration_since(SystemTime::UNIX_EPOCH)
405405
.unwrap();
406406

407+
let sanitized_label = label
408+
.chars()
409+
.map(|c| {
410+
if c.is_alphanumeric() || c == '_' {
411+
c
412+
} else {
413+
'_'
414+
}
415+
})
416+
.collect::<String>();
417+
407418
Self {
408419
items: Default::default(),
409420
label: Arc::new(Mutex::new(label.to_owned())),
410421
modified: Arc::new(Mutex::new(created)),
411422
alias: Arc::new(Mutex::new(alias.to_owned())),
412423
item_index: Arc::new(RwLock::new(0)),
413-
path: OwnedObjectPath::try_from(format!("/org/freedesktop/secrets/collection/{label}"))
414-
.unwrap(),
424+
path: OwnedObjectPath::try_from(format!(
425+
"/org/freedesktop/secrets/collection/{sanitized_label}"
426+
))
427+
.expect("Sanitized label should always produce valid object path"),
415428
created,
416429
service,
417430
keyring: Arc::new(RwLock::new(Some(keyring))),

0 commit comments

Comments
 (0)