From 364542b2c50c405a5cb2ecfdaa7bf4583bcf84aa Mon Sep 17 00:00:00 2001 From: Joe Eftekhari Date: Wed, 4 Mar 2026 20:50:09 -1000 Subject: [PATCH] fix: reject DEL character (0x7F) in input validation (#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. --- .changeset/fix-reject-del-char.md | 9 +++++++++ src/validate.rs | 10 ++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/fix-reject-del-char.md diff --git a/.changeset/fix-reject-del-char.md b/.changeset/fix-reject-del-char.md new file mode 100644 index 0000000..a117d22 --- /dev/null +++ b/.changeset/fix-reject-del-char.md @@ -0,0 +1,9 @@ +--- +"@googleworkspace/cli": patch +--- + +fix: reject DEL character (0x7F) in input validation + +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. diff --git a/src/validate.rs b/src/validate.rs index d6e99d2..cfefd60 100644 --- a/src/validate.rs +++ b/src/validate.rs @@ -118,9 +118,10 @@ pub fn validate_safe_dir_path(dir: &str) -> Result { Ok(canonical) } -/// Rejects strings containing null bytes or ASCII control characters. +/// Rejects strings containing null bytes or ASCII control characters +/// (including DEL, 0x7F). fn reject_control_chars(value: &str, flag_name: &str) -> Result<(), GwsError> { - if value.bytes().any(|b| b < 0x20) { + if value.bytes().any(|b| b < 0x20 || b == 0x7F) { return Err(GwsError::Validation(format!( "{flag_name} contains invalid control characters" ))); @@ -388,6 +389,11 @@ mod tests { assert!(reject_control_chars("hello\nworld", "test").is_err()); } + #[test] + fn test_reject_control_chars_del() { + assert!(reject_control_chars("hello\x7Fworld", "test").is_err()); + } + // -- encode_path_segment -------------------------------------------------- #[test]