in reply to Security issue and solution for terminal command accessed by public user
The simple solution is to only accept values that match numeric values and known units:
use Regexp::Common; my %units = map ($_,1), qw[ miles kilometers pounds kilograms ... ]; my( $num, $from, $to ) = getUserInput(); die 'Bad number input' unless $num =~ /^\s*$RE{num}{real}\s*$]; die 'Bad units input' unless exists $units{ lc $from } and exists $units{ lc $to ); my $res = `units $num $from $to`;
|
|---|