Re: securing include()
| From: | Jason Wong | Date: | Wed, 16 Apr 2003 09:11:17 +0000 |
| Subject: | Re: securing include() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144087@lists.php.net to get a copy of this message | ||
On Wednesday 16 April 2003 16:17, Alexei Matveev wrote:
> Hi, Everybody,
>
> I am new in this list, hoping the
> question matches the topic:
>
> How secure is this include($body) against
> malicious body=/etc/passwd ???
>
> $body = $GET['body'];
>
> $body = preg_replace("/\.\./","XX",$body);
> $body = preg_replace("|^/|","X",$body);
>
> include("./" . $body);
>
> Are there more elegant ways to do the same?
Use basename() to strip off any leading paths leaving just the filename. Then
prepend your own base directory.
--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
/*
Time goes, you say?
Ah no!
Time stays, *we* go.
-- Austin Dobson
*/