假设给出了以下Perl代码:
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}'`;
Run Code Online (Sandbox Code Playgroud)
代码显然不安全,但假设唯一可以改变的是第2行的过滤代码.
我的问题:
请注意:
首先,鉴于您关心安全性,我建议您研究一下污点模式.至于允许shell可见的最小字符集,最好不要让shell看到任何字符:
my $output = do {
local $/;
open my $pipe, "-|", "/path/to/some/command", $user_supplied_string
or die "could not run /path/to/some/command: $!";
<$pipe>;
};
Run Code Online (Sandbox Code Playgroud)