in reply to Security with open() in CGI scripts
which makes you worry about $theme->{ThemeDir} why notmy $template = $theme->{ThemeDir}."index.html";
Now everything is under control... if $theme ever contains anything it isn't supposed to then the worst thing that can happen is the hash lookup fails and the open fails. No way malicious code can hurt you, all because you insulated your open by using a hash.my %themes = {1 => '/dir1/', 2 => '/dir2/', 3 => '/dir3/'}; my $theme = param(theme); my $filename = "$themes{$theme}.index.html"; open (FILE, $filename);
Of course, this isn't always practical, but most of the time it's a good idea. This won't work if you let users name their own files, and upload (or create) those files directly on the server, but if you're doing that you're gonna have to jump through more hoops than we've covered here in order to maintain security.
Gary Blackburn
Trained Killer
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Security with open() in CGI scripts
by brianarn (Chaplain) on Feb 26, 2002 at 05:48 UTC |