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.
This commit is contained in:
@@ -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.
|
||||
+8
-2
@@ -118,9 +118,10 @@ pub fn validate_safe_dir_path(dir: &str) -> Result<PathBuf, GwsError> {
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user