Is there a way to safely encode / pass arguments to a shell command where the argument might be binary? I'm executing a command from within a PHP script that allows for user data. For security, however, I obviously want this data escaped. Moreover, sometimes the data may be binary in nature so simple quoting of the shell command doesn't seem like it would suffice. What's the best approach for making sure a shell command's argument is properly escaped even if the argument data is binary?
1 Answer
You can encode it as base64 in PHP using base64_encode(), pass it to the shell, then decode it in the shell using base64 --decode
.