User Folders - best approach?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
bread_man
Forum Newbie
Posts: 6
Joined: Thu Aug 31, 2006 1:19 pm
Contact:

User Folders - best approach?

Post by bread_man »

I started to touch base on this in the security forum, but want to expand a little more and thought this forum was a little more appropriate.

I have a little blogging service. Each user has a folder directly off the webroot, such as

http://www.mysite.com/user1/ (public_html/user1)

In that folder is about 10 php pages and 2 sub-folders, movies and photos.

The movies and photos folder permissions are set to 0777 so my php scripts can move uploaded items there from the temp folder.

So I'm already doing something bad - having folders with write permissions below the web root.

But now I am writing a user creation php script for signing up a new user and the only way to be able to create a new folder for that user is to make the web root itself writable. Seems very bad to do this.

I know other people have had other user systems similar to this and I was hoping someone could shed some light on the best approach? Anyway to get these items above the webroot without modifying the apache httpd.conf? It has to be expandable - more users will be added on the fly.

Thanks for any help!

bread

*edit: got above and below mixed up in my first post :P
Last edited by bread_man on Fri Sep 01, 2006 8:55 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I think it depends on who has write access to those folders. If it is only your PHP code and you are controlling what users can do within the code then is should be fine.
(#10850)
User avatar
bread_man
Forum Newbie
Posts: 6
Joined: Thu Aug 31, 2006 1:19 pm
Contact:

Post by bread_man »

The apache user has write access in order for the php scripts to write to those folders. In the upload scripts, I am doing everything I know to ensure nobody is uploading malicious files - checking mime types and using gd and php-ffmpeg to validate uploaded images and movies. I just keep hearing over and over that you're not supposed to have writeable folders below the web root but I can't honestly say I know why.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

As long a you are in control of system access to those folders and take appropriate precautions to control what gets written, then having writable folders should not be a problem. I would suggest using Defense in Depth strategy by making sure that you are taking precautions at every level and step you can think of.
(#10850)
Post Reply