Score:1

Why does Drupal harden permissions of the /web/sites/default directory and files?

sh flag

I understand that Drupal hardens permissions of the /web/sites/default directory and its files, each time that the system_requirements() function is called, typically after each composer require operation.
The particular hardening is removing the write permission from the user of the Drupal file tree, and to soften that hardening one would have to do chmod u+w web/sites/default.

If I understand correctly, why does Drupal remove the write permission from the user of the Drupal file tree?
What typical problem does it prevent, or solve?

Score:4
id flag

The settings.php file contains the database password and username in plain text and, once created, must be set so that only appropriate users can read it. That usually means removing read permissions for the "other" user.

https://www.drupal.org/docs/administering-a-drupal-site/security-in-drupal/securing-file-permissions-and-ownership

It is not particularly clear in this question if you are asking about files or about the sites/default directory. In the case of hardening permissions on the sites/default directory itself, that is to prevent the addition of files.

The original reasoning is in this seventeen-year-old issue.

The general approach here is that, because we do not know the security setup of the webserver, we apply our permission changes to all three digits of the file permission (i.e. user, group and all).

Power users who understand filesystem details may wish disable these protection via a documented configuration in settings.php.

alhemist avatar
sh flag
Why should I want to prevent the user account that I myself use to manage my Drupal installation from writing anywhere inside it? By "writing" I mean adding files to `sites/default` or editing an existing file there such as `settings.php`. I mean, if that directory and its files are owned by my user account and are grouped in the group of my user account and others cannot access it, then why should I expect Drupal to harden it so that even I myself couldn't write in it (unless I soften the hardness)?
id flag
I don't think we can answer questions about what you should want or what you should expect, as those are your private thoughts.
alhemist avatar
sh flag
Sure, let my try that again, what is the logic in making Drupal removing the `write` permission from the user account which owns `sites/default` and its files, grouped in a group of the same name and that other user accounts can't access?
id flag
As I quoted in the answer “we do not know the security setup of the webserver”. In some shared hosting, the web server user is the same as the shell account user, for example.
alhemist avatar
sh flag
Alright, let's take that scenario in which the shell user account is the Drupal user account of `sites/default`. Why make that user account remove itself the `write` permission if it can also give it back to itself? Maybe in other scenarios, it can't give it back to itself.
No Sssweat avatar
ua flag
`Why make that user account remove itself the write permission` It's a security child lock. It's better to be safe than hacked, m'kay?
alhemist avatar
sh flag
@NoSssweat if any user account of Drupal can remove this permission but then immediately bring it back, then I don't think it's a lock at all. What am I missing?
I sit in a Tesla and translated this thread with Ai:

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.