Conversation
Beyond being risky, many of these uses of eval were actually vulnerable to shell injection, if the inputs are untrusted. Switching all cases to nameref variables improves both security and readability, while only raising the minimum bash version from 4 to 4.3.
|
Test look good. |
|
For what it's worth I've known about this since the creation of the library, and I'll be honest, I'm not sure why we should worry about the scenario being described here. I see the example, but that's not an example of an exploit, it's just execution of commands. The effect is no different than someone doing So why is this a cause for alarm? I'm not necessarily against the patch (although even a minor version change might cause problems in some places), I'm just curious about the justification for the concern. |
|
Imagine a scenario where the script is hooked into some automation process, where the library is used to parse the arguments provided from some untrusted source. In this scenario you're setting the script as the trust boundary, granting permission for the script to be run with some arbitrary arguments, but no more. In addition to the possibility of injection, the version with |
I understand that scenario, but ensuring the safety of the inputs in that scenario is not cmdarg's job, any more than it's the SQL library's job to ensure that little Bobby Tables is properly handled. The script in this case is running inside of a privileged shell as the user; anything and everything cmdarg does (including the execution of validator functions) will happen with the privileges of the user running the current shell. It is the responsibility of the program calling the library to ensure the library is receiving sane inputs.
I find this justification a lot more compelling. What are some examples of this behavior? |
In my original example the expected and correct behaviour would be for the array variable to be set to contain the provided input, like but with eval, the array is actually set as |
|
Fair point. Thanks for indulging me. There is a problem with CI but that doesn't appear related to your changes. The tests look good. Merged |
Beyond being risky, many of these uses of eval were actually vulnerable to shell injection.
Switching all cases to nameref variables improves both security and readability, while only raising the minimum bash version from 4 to 4.3.
A simple example of an exploit against the eval-based version follows
run like
./pwn.sh -a '"; whoami; #'