Score:0

Insecure Apache + mod_userdir configuration

de flag

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.

Alex avatar
us flag
Maybe it's worth moving this question to Information Security forum? https://security.stackexchange.com/
Juanan avatar
de flag
Agree. I don't know if can I move the question myself or should I have more reputation points in order to do that?
Alex avatar
us flag
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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.