|
|
|
Clear questions and runnable code get the best and fastest answer |
|
| PerlMonks |
Sanitizing user-provided path/filenamesby Fastolfe (Vicar) |
| on Feb 07, 2001 at 00:24 UTC ( [id://56767]=note: print w/replies, xml ) | Need Help?? |
|
If you really must rely on user-provided data that maps directly to path/filenames, and can't use a token system to represent the same thing, I would explicitely declare what your valid "root" directory is, and do a check like this:
Keep in mind, though, that this still lets them ../ their way anywhere they want under your declared $ROOT, so if you're expecting a filename to be in a certain place or under a certain hierarchy under your $ROOT, you need to do some additional checking/tokenizing to be sure that it actually does end up there. All this code does is keep the user sandboxed. I too highly recommend reading perlsec and using taint-checking (-T) to better prepare yourself for potentially unsafe user-provided data.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||