Doc #52835 [Wfx]: readfile sample allows directory download

From: Date: Tue, 14 Sep 2010 23:26:04 +0000
Subject: Doc #52835 [Wfx]: readfile sample allows directory download
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5030@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52835&edit=1 ID: 52835 User updated by: kittya at breyfamily dot net Reported by: kittya at breyfamily dot net Summary: readfile sample allows directory download Status: Wont fix Type: Documentation Problem Package: Documentation problem PHP Version: 5.3.3 Assigned To: aharvey Block user comment: N New Comment: The example may not be so contrived after all. I found the example when I was looking for code to do just what the example does. Before submitting the documentation problem report, I used the example almost verbatim in a project: http://sermonsontheweb.svn.sourceforge.net/viewvc/sermonsontheweb/trunk/Web/ChurchWebSite/Sermons/Download.php?revision=199&view=markup I noticed the problem when performing security testing. There are more elegant solutions with rewrites, but the approach in the example is simple and very portable. Regarding is_file, perhaps links and special files cases will be OK. If links would be followed, and the stream from special files would be read, that would be appropriate in most scenarios. Previous Comments: ------------------------------------------------------------------------ [2010-09-14 12:35:11] aharvey@php.net Actually, on second thoughts, I'm going to leave this as it is. It's an obviously contrived example and is_file() isn't necessarily sufficient anyway, since it doesn't cover links and special files. Closing won't fix. ------------------------------------------------------------------------ [2010-09-14 10:29:13] kittya at breyfamily dot net Description: ------------ For the readfile function, sample 1, "Forcing a download using readfile()" uses file_exists to check whether $file is valid. However, if there is a directory by the name of $file, the sample code causes PHP to try to download the directory, which will likely be meaningless to the client. Expected result: ---------------- The sample should use is_file. Actual result: -------------- The sample currently uses file_exists. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52835&edit=1

« previous php.doc.bugs (#5030) next »