I am trying to set up PHP sessions for suPHP (see here). I need to have my php validation file owned by the user so that when suPHP kicks in, it will do so for the correct user. However, I also don't want the user to have access to that file, o.w. they can edit it to just return true rather then actually check the database.
My first attempt was something like this (where Apache runs as user www-data
)
/etc/validate
├── [drwx------ www-data ] user1
│ └── [-rwx------ user1 ] validate.php
/var/www/
└── [drwx------ user1 ] user1
└── [-rwx------ user1 ] index.html
Then have the web pages redirect to the validate page, which would validate, then return /var/www/user1/index.html
RewriteCond %{REQUEST_URI} !^/xyz
RewriteRule ^(.*) /etc/validate/user1/validate.php?uri=$1
However suPHP complains that I am accessing something outside of my docroot (/var/www/user1
). I don't want to set the docroot to /
and updating suphp.conf
file so that check_vhost_docroot=false
, doesn't fix (and I don't it is meant to fix this). Therefore, instead I just moved /etc/validate
into /var/www
like so (it's a little messy, I know)
/var/www/
└── [drwx------ user1 ] user1
├── [-rwx------ user1 ] index.html
└── [dr-x------ www-data ] validate
└── [-rwx------ user1 ] validate.php
So now the validate file is
- Within docroot
- Owned by user1
- Not editable by user1
But now if I try to load the page I get the following error
Directory /var/www/user1/validate is not owned by user1
At this point I am losing my patience, so I just stick another dummy folder in there so the file structure looks like so
/var/www/
└── [drwx------ user1 ] user1
├── [-rwx------ user1 ] index.html
└── [dr-x------ www-data ] validate
└── [drwx------ user1 ] dummy
└── [-rwx------ user1 ] validate.php
Now, when I try to load the page, Apache tells me "You don't have permission to access xyz on this server." where xyz
is whatever comes after my domain name. I don't know why Apache is telling me that because I am not trying to access the trailing values as a file/folder. I think, the redirect is failing and Apache just assumes it is the hard link that is failing.
Can anyone tell me what I am doing wrong or provide an alternative way to prevent users from being able to edit their files. It could not get into directory dummy
because its permissions were rwx------
and only user1
could cd
into it. When I changed the permissions from 0700
to 0755
, it went back to suPHP errors. So the question now becomes: how do I get suPHP to execute scripts when one of its upstage directories is owned by someone else?
EDIT: I realize now why Apache was complaining. It could not get into