Assume that the following Perl code is given:
my $user_supplied_string = &retrieved_from_untrusted_user();
$user_supplied_string =~ s/.../.../g; # filtering done here
my $output = `/path/to/some/command '${user_supplied_string}'`;
The code is clearly insecure, but assume that the only thing that can be changed is the filtering code on line #2.
My question:
- What is the minimal set of characters that needs to be filtered on line #2 to make the above code secure?
Please note:
- Whitelisting is not an option in this case, so please keep your answer focused on what to filter out to make it secure. And more specifically; what is the minimal set of characters to filter out to make it secure? Everything else is off-topic.
- Make sure your answer addresses the question stated ("What is the minimal set of characters that needs to be filtered on line #2 to make the above code secure?"). If your answer does not address that very specific question then don't post. Thanks.