Skip to content

Commit 364542b

Browse files
authored
fix: reject DEL character (0x7F) in input validation (npm#122)
The reject_control_chars helper rejected bytes 0x00-0x1F but allowed the DEL character (0x7F), which is also an ASCII control character. This could allow malformed input from LLM agents to bypass validation.
1 parent 263a8e5 commit 364542b

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

.changeset/fix-reject-del-char.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@googleworkspace/cli": patch
3+
---
4+
5+
fix: reject DEL character (0x7F) in input validation
6+
7+
The `reject_control_chars` helper rejected bytes 0x00–0x1F but allowed
8+
the DEL character (0x7F), which is also an ASCII control character. This
9+
could allow malformed input from LLM agents to bypass validation.

src/validate.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ pub fn validate_safe_dir_path(dir: &str) -> Result<PathBuf, GwsError> {
118118
Ok(canonical)
119119
}
120120

121-
/// Rejects strings containing null bytes or ASCII control characters.
121+
/// Rejects strings containing null bytes or ASCII control characters
122+
/// (including DEL, 0x7F).
122123
fn reject_control_chars(value: &str, flag_name: &str) -> Result<(), GwsError> {
123-
if value.bytes().any(|b| b < 0x20) {
124+
if value.bytes().any(|b| b < 0x20 || b == 0x7F) {
124125
return Err(GwsError::Validation(format!(
125126
"{flag_name} contains invalid control characters"
126127
)));
@@ -388,6 +389,11 @@ mod tests {
388389
assert!(reject_control_chars("hello\nworld", "test").is_err());
389390
}
390391

392+
#[test]
393+
fn test_reject_control_chars_del() {
394+
assert!(reject_control_chars("hello\x7Fworld", "test").is_err());
395+
}
396+
391397
// -- encode_path_segment --------------------------------------------------
392398

393399
#[test]

0 commit comments

Comments
 (0)