What are some common security risks associated with executing shell scripts in PHP?

When executing shell scripts in PHP, one common security risk is the potential for command injection attacks if user input is not properly sanitized. To mitigate this risk, it is important to validate and sanitize any user input before using it in shell commands. Additionally, using escapeshellarg() or escapeshellcmd() functions can help prevent malicious code injection.

$user_input = $_POST['input'];
$validated_input = escapeshellarg($user_input);

// Execute shell script with validated input
$output = shell_exec("sh script.sh " . $validated_input);