I currently tying to spread the knowledge about "Safe file system permissions" where I point to this module. Because some user on sharing hosting platforms are trying to get this test "green" I tested the following situation:
On a test system I changed the ownership of drupal files to the webserver user and the test "Safe file system permissions" became "red". On the next step I removed writing permissions of this user in the complete webroot with "chmod -R u-w". Now the test was "green". And here I see a problem: The webserver has the possibility to get write access to a folder with php command "chmod". For example:
chmod("misc", 0777);

As I understand this module is currently using writing tests? But to keep aware of the situation described above there should also be a test for the ownership of files and directories in my opinion.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

C_Logemann created an issue. See original summary.

aohrvetpv’s picture

Checking that the web server user does not own files inside the web root but outside the files directory would be a good enhancement, I think. (The web server will create files in the files directory for cache, uploads, etc. and will have ownership, so there would need to be an exception for that directory.)

The chmod risk seems to me practically pretty low though. An attacker would have to be able to execute a chmod command. How would they do that? If an attacker can execute arbitrary PHP, the site is already compromised, right. So is there an example of a more practical attack? (Or am I wrong about the chmod risk?)

c-logemann’s picture

The exceptions for ownership should be the same as for the writing permissions. There could also be more folders as "files" and "tmp" like special cache folder of the boost module.

We should avoid that a successful attacker can place additional code on the file system. With drupalgeddon we had mass exploits of the menupath with placing additional code in the file system via php to turn drupal systems into SPAM-machines. Maybe this exploits can be extended with additional chmod commands.

c-logemann’s picture

Since today I already have an idea how to open the write access if there is a problem like on drupalgeddon but I didn't want to share this information on this public forum. If the security team is interested we can discuss this in the closed security forum. But I believe they can also imagine how to bypass this small barrier of write access when the webserver user is the owner of an directory but currently it's write protected.
With my work on my new chmod-module I found a solution based on a fast exec-find-solution with searching all files and folders where the webserver is the owner. This is the basement of a following chmod-command inside a single exec-command. In the same way I can write a test for this module but maybe there are problems with the compatibility on php setups where the usage of exec is limited. On the other side I see some possibilities for a better performance with the current "Safe file system permissions"-test if we use the find command of the operating systems if exec and this command is available maybe as an alternative testing method.

smustgrave’s picture

Could this be useful for D10 as well?

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)
smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

I'm keeping an eye on the 7.x branch of this module, reviews and majors, but
active work is going toward 2.x (supporting D10)

If valid for 2.x please reopen

c-logemann’s picture

The main problem is now addressed in this issue: #3454866: file check is problematic "green" when not test with chmod

c-logemann’s picture

Title: "Safe file system permissions" should test the ownership of files and directories » There should be a new test for ownership of files and directories
Version: 7.x-1.x-dev » 3.0.x-dev
Status: Closed (outdated) » Active

The related issue is more important because it directly checks the the ability to change permissions not only the potential to do so. The file owner check should maybe be separate because there could be server strategies to avoid changes of permissions like chattr and the ownership of a file cannot be used for changing permissions. And if this is the case it would be helpful to deactivate this check.
(Edit: corrected logic of first sentence)

c-logemann’s picture

Assigned: Unassigned » c-logemann

Because "SecurityReviewData->findWritableFiles" is already checking the fileowner I think it would be a good idea to move this code to another function which could return two values: writable and possibly writable because of ownership. For backward compatiblity we can keep the old function as wrapper.

smustgrave’s picture

Hello @c-logemann since it's been a few months wonder if you want me to un-assign?

c-logemann’s picture

Assigned: c-logemann » Unassigned

I hope in winter I find some time to push the file permission issues forward if no one else step in.

smustgrave’s picture

Sounds good! I'll be around and appreciate the super quick reply.

smustgrave’s picture

since it's been a year wonder if this is still a desired feature.

ressa’s picture

I recently looked at permissions, and it can be challenging to get them right, so if adding this test helps assure that the checks are working as intended, it would be nice.

smustgrave’s picture

This test will most likely require a configuration form asking who the owner should be.

So if the configuration isn’t set then the check will throw a warning message.

c-logemann’s picture

@smustgrave Because there could be mixed ownership situation we need a logic that detects that the webserver is the owner code files or maybe everything which is not intended to be writeable like the public and private files folder etc.

c-logemann’s picture

Assigned: Unassigned » c-logemann

But the idea of a configuration or better setting variable is good. If a test runs via webserver we ca get this information directly and maybe give a warning if setting is not present or different.

smustgrave’s picture

Assigned: c-logemann » Unassigned
smustgrave’s picture

I don't think this needs it's own check, that would be even more performance hit to scan the directories twice.

Instead think we need
1. Configuration with text field for ownership of files/directories
2. Update hook adding this
3. Schema entry
4. In the FilePermissions check if this field is valid then while we check permission we check ownership at the same time. Thoughts?

smustgrave’s picture

Version: 3.0.x-dev » 4.0.x-dev