Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting input for security

Status
Not open for further replies.

busfault

Programmer
May 12, 2005
1
US
I am workikng on a script that takes the output of an application on my liunx server and prints the output. I have text from the user run with the program like such:
print `app $word`;
After realizing that this would allow &cmds and redirects I added print `app \"$word\"` which seems to work but I would like to know how to strip everything except a-zA-Z and typical word letters like '.
Also is there a better way of running an application?
Thanks,
Tom
 
strip all but a-zA-Z:

my $word = 'c&l#@e>an+_-=ed&&';
$word =~ s/[\W_]//g;
print $word;
 
If you turn on `taint mode' (the -t switch on your shebang line), Perl will protect you from user-inputted data which may be used in an undesired way. You'd then have to untaint that data with a regexp before Perl will let you use it for things like filenames and commands.
Code:
my ( $untainted ) = $word =~ /^([a-zA-Z.]+)$/;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top