Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Welcome to the Monastery
 
PerlMonks  

Re: Security issue and solution for terminal command accessed by public user

by BrowserUk (Pope)
on Jul 06, 2012 at 18:31 UTC ( #980351=note: print w/ replies, xml ) Need Help??


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`;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


Comment on Re: Security issue and solution for terminal command accessed by public user
Download Code
Re^2: Security issue and solution for terminal command accessed by public user
by Anonymous Monk on Jul 06, 2012 at 19:14 UTC

      Why?


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Re^2: Security issue and solution for terminal command accessed by public user
by keenlearner (Acolyte) on Jul 07, 2012 at 05:14 UTC

    Hi Thanks, I have thought of this. But I was wondering if there's a lazy way to bypass this method, cause then I have to find all the supported units and list in the perl code, that's not a big problem but if in the future if I add a new unit in "units", then have to add in the code also.

      It is the safest way.

      If you trust the quoting modules to handle everything a malicious user might throw at it, buffer overflow attempts and all the other 'ploits the devious minds must expend hundreds of hours dreaming up, go for it.

      I'm not the paranoid type, but I see the ongoing arms race seemingly undampened by the millions of dollars and thousands of hours of expertise that large organisations like MS, Google, Apple et al. throw at similar problems. Am I going to trust the efforts of a lone CPAN author, given that the bad guys have only to download the module to look inside to search for weaknesses?

      When the alternative is safer and actually easier, why risk it.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980351]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-04-16 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (418 votes), past polls