Skip to content

Commit 9f5c87d

Browse files
authored
Merge pull request #391 from Dstack-TEE/vmm-app-name
vmm: Accept more chars in cvm name
2 parents b7969e1 + cf63b9a commit 9f5c87d

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

vmm/src/main_service.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ fn app_id_of(compose_file: &str) -> String {
5151
truncate40(&hex_sha256(compose_file)).to_string()
5252
}
5353

54-
/// Validate the label of the VM. Valid chars are alphanumeric, dash and underscore.
54+
/// Validate the VM label, restricting it to a safe character set to prevent injection vectors.
5555
fn validate_label(label: &str) -> Result<()> {
56-
if label
57-
.chars()
58-
.any(|c| !c.is_alphanumeric() && c != '-' && c != '_')
59-
{
60-
bail!("Invalid name: {}", label);
56+
fn is_valid_label_char(c: char) -> bool {
57+
c.is_ascii_alphanumeric()
58+
|| matches!(
59+
c,
60+
'-' | '_' | '.' | ' ' | '@' | '~' | '!' | '$' | '^' | '(' | ')'
61+
)
62+
}
63+
if !label.chars().all(is_valid_label_char) {
64+
bail!("Invalid name: {label}");
6165
}
6266
Ok(())
6367
}

0 commit comments

Comments
 (0)