perlquestion
ajt
Hi, a while ago I asked the wisdom of a simple site mapping tool, (see [id://120494]). I got a few useful messages - many thanks, and so went ahead and built it. It works great, and I'm happy with it, except that I know it's got at least one big security hole!
<p>I'm working within a secured intranet, so I don't expect many hacking attempts, but you can never tell, plus I can't be sure that someone else won't use the script within the company in a less secure environment - who ever reads warning and comments when you are in a hurry?
<p>The problem lies around the way that the script works out which directory tree to map. Here is a summary of how it works:
<ul>
<li>HTML page containing an XML tag to the script is called by the browser. The templating system calls the script, passing some parameters to the script to let it know where it was called from.</li>
<li>The script starts and works out on which virtual host it was called from, and looks up that host's config file. If it can't find it, eg fake virtual host, then it dies.</li>
<li>After this it works out where it was called from, (via the parameters) and then dies if start of the physical path does not match the one it's allowed to use.</li>
<li>It passes the directory of to File::Find, and away it goes.</li>
</ul>
<p>The obvious problem with this is that if you pass by hand a path such as <code>/allowed/../../notallowed</code>, where the approved path is <code>/allowed/</code>, then this gets through, and then File::Find then traverses a space it's not supposed to (directory permissions aside).
<P>I've done the obvious of obliterating any "<code>..</code>", but I know that there are many more ways to bypass this. Taint and detainting won't help directly either.
<p>CHROOT isn't an option on my NT box, and annoyingly NT permissions don't prevent much either - as currently set. On a Linux box (next phase) I should be able to use CHROOT and file permissions to control the script a bit better, but I'd like the script to be more robust by default.
<p><strong>QUESTION:</strong> How do I take in a path from the outside, and verify that it's safe to pass to File::Find?
<p>As ever, humble thanks in advance.