validate_command_arg

Function validate_command_arg 

Source
pub fn validate_command_arg(arg: &str) -> Result<String>
Expand description

Validate command arguments to prevent command injection

This function checks for shell metacharacters and returns an error if any are detected. Use this when building shell commands from user input.

§Security Concerns

Blocks the following shell metacharacters:

  • Pipes: |, ||
  • Command separators: ;, &, &&
  • Redirection: <, >, >>
  • Command substitution: `, $(, )
  • Wildcards: *, ?
  • Null byte: \0

§Example

use mockforge_core::validation::validate_command_arg;

assert!(validate_command_arg("safe_filename.txt").is_ok());
assert!(validate_command_arg("file; rm -rf /").is_err());
assert!(validate_command_arg("file | cat /etc/passwd").is_err());