i'm allowing users to upload files to a directory on a website. i am limiting the file based on MIME type (JPG). BUT i do not know what the correct permissions for the directory and for the individual files should be so that a visitor to the website is able to view the files once uploaded.
the only thing i can set the directory to in order to get it to work is 777, and i know that exposes my butt end to the world. anything else gives a "you do not have permission to view this directory" error.
But there are other things that can be done by the server admins to block access, so setting the permissions may not give you what you want.
One other solution is to use the .htaccess file (see //www.freewebmasterhelp.com/tutorials/htaccess/ or Google "htaccess tutorial".) If you do this, you may also want to set .htpasswd and .htgroup
Unfortunately using 777 is the only way to allow a web browser upload to a directory. The user that runs the web server *should* be a user that has no privileges on the machine. So you have to open the directory to everyone to allow the browser to write.
You can get around this by setting up users for the website and then scripting on the backend to check the users before uploading. (Like DPC does.)
The directory should only need execute permissions if you want users to be able to read files from that directory, or read/execute if you also want them to be able to see a directory listing. Execute only permission for everyone would be 111, read/execute 555. You probably want something a bit less restrictive, like 755 (read/write/execute for the owner of the directory, read/execute for the group and everyone else).
The files themselves are going to have to be at least 444 (read only by everyone), but again you may want to make that 644 (read/write by the owner, read only by everyone else).
You don't need 777 on the directory. You should just need 700 (sometimes 770 works better, depending on how stuff is set up) (+rxw for owner or owner and group), with the owner of the directory being the user that the webserver runs as. Of course, you'll have to find that out and be able chown the directory. I assume the reason you need to have 777 is because the owner and group of the directory is different than that the webserver runs as.
You can find it either on the configuration file (httpd.conf, you're running Apache, don't you) or typing "ps -ef" and looking for something that looks as a web server on the rightmost colunm. The user is on the first column. It's usually "http" or "httpd" for the web and "ftp" for the ftp server. YMMV.
chgrp the files to the web user, often www-data or just www, then set perms 644 or 640 if you don't want other users on the system to see them, and 755 or 750 for ones that need to be executed (cgi and some php stuff).
You can find it either on the configuration file (httpd.conf, you're running Apache, don't you) or typing "ps -ef" and looking for something that looks as a web server on the rightmost colunm. The user is on the first column. It's usually "http" or "httpd" for the web and "ftp" for the ftp server. YMMV.
no dice. still the only way i can write to the directory is with 777.
i tried to set the group to "nobody" because that's the owner of the cold fusion process (yes, i'm using cold fusion. shut up and quit laughing.) and i still can't do anything unless the directory is 777.
how big a security risk is that, having the permissions wide open like that?
Well, you generally don't want to let your webserver write... unless it owns the files it's writing to, which is the point of the chgrp. What do you mean by "the only way i can write to the directory..."? How are you trying to write to it?
it's a cold fusion script that allows individuals to upload files of a limited MIME type (JPEG) and a limited size. if the permissions are not set so that CF can write the file to the directory on the server, it just ignores it and moves on (no error message).
Then make that directory owned by the user (nobody) and make the group apache (just in case it's funny about these things) and set the directory to 775. That'll let apache and cf write and execute but not other users. If you only want cf to write, and not apache, set it to 755.