Score:0

Prevent Apache from writing to a file

jp flag

I have a website based on a CMS, running on Apache 2.4/PHP7.4. The CMS has an admin interface and changes you make there are written to config files inside the web root (/var/www/html/...). As a crude security measure, I thought I'd prevent writing to these files by changing file permission and ownership.

Apache runs as the www-data user, and the normal permissions for the files are 644 www-data:www-data. If I chmod and chown the files to 444 otheruser:otheruser and click "save" inside the CMS, the file is still written and it is also changed back to 644 www-data:www-data.

The containing directory has 777 otheruser:otheruser (for some reason). otheruser is member of the sudo group, if that somehow matters.

Is my approach doomed? What gives Apache/PHP the power to control these files regardless of ownership and permissions? Does it have to do with the fact that one of the many apache2 processes runs as root?

jp flag
777 on the directory means that anyone can remove and recreate any files from that directory regardless of the permissions of the file itself.
jp flag
Oh, seems I've missed something fundamental regarding how permissions work. Thanks @AlexD!
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.