0

TL;DR: How can I enable mod_userdir in a secure way? (meaning: each user should be able to create and serve their content in ~/public_html but they shouldn't be allowed to read each others content nor directly - cat /home/userX/public_html/file- neither through PHP functions (file_get_contents('/home/userX/public_html/file'))

Details: I have configured Apache with mod_userdir for offering my users the option to serve their content dropping files in their ~/public_html folder. In order to protect file access and to avoid that any user could read others' files, I have configured the following permissions:

/home/userA user.user drwx--x--x (711)  
/home/userA/public_html  user.user drwxrwx--x  (771)

I have added www-data to each user's group: usermod -a -G user www-data (it could also work creating a group and adding all users, including www-data, to it)

All the configuration works as expected. Any user can access its content from https://server/~user and they can't read any others' files:

userA@ubuntu:/home$ cat userB/public_html/index.php 
cat: userB/public_html/index.php: Permission denied

So far, so good. But the problem is that, as Apache is running as www-data and it has group-access to any file inside /home/*, any user can create a PHP file to read others' content using functions like exec, system, file_get_contents, etc.

I know that I can disable such functions from executing adding them to the disable_functions block in php.ini but I see this as a patch, not a solution. So it seems to me that there should be other, more secure, way of configuring this userdir-enabled Apache configuration. I have searched for a way to do this properly but haven't found a proper solution.

Juanan
  • 261
  • 3
  • 7
  • 1
    Maybe it's worth moving this question to Information Security forum? https://security.stackexchange.com/ – Alex Sep 27 '21 at 07:07
  • Agree. I don't know if can I move the question myself or should I have more reputation points in order to do that? – Juanan Sep 27 '21 at 12:47
  • 1
    If you think it's a good idea, flag your post as described here: https://meta.stackexchange.com/questions/184657/how-do-i-transfer-this-question-asked-on-stack-overflow-to-the-math-stack-exchan – Alex Sep 27 '21 at 17:37

0 Answers0