Problem/Motivation

In #3550828: .htaccess file is writable, using the current Securing file permissions and ownership doc page it was concluded that 440 is the recommended permissions for .htaccess. But newly generated .htaccess files have 444 permissions, as can be seen here, where it's defined:

if (@file_put_contents($file_path, $contents)) {
  return @chmod($file_path, 0444);
}

https://git.drupalcode.org/project/drupal/-/blob/main/core/lib/Drupal/Co...

On the Securing file permissions and ownership page it is recommended to only grant permissions to user or group, and not grant any permission to other, since o= is used for all commands:

The project root public_html folder contains composer.json, composer.lock, vendor, and web.
[...]

$ cd /var/www/example.org/public_html/web
$ chown -R deploy:www-data .
$ find . -type d -exec chmod u=rwx,g=rx,o= '{}' \;
$ find . -type f -exec chmod u=rw,g=r,o= '{}' \;

... and:

For the "files" directory in the sites/default directory and any other site directories in a multi-site installation, the permissions are slightly different because the www-data user must have write permission to the directory:

$ cd /var/www/example.org/public_html/web/sites
$ find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
$ find ./*/files -type d -exec chmod ug=rwx,o= '{}' \;
$ find ./*/files -type f -exec chmod ug=rw,o= '{}' \;
$ find ./*/files/.htaccess -type f -exec chmod ug=r,o= '{}' \;

So it seems counterintuitive to create the .htaccess file with 444, since everywhere else, the other user has no permissions at all.

Steps to reproduce

See that the default permissions for .htaccess is 444, but 440 is recommended on Securing file permissions and ownership.

Proposed resolution

Decide if it is better to create .htaccess files with 440, and not 444 permissions.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3620015

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

ressa created an issue. See original summary.

ressa’s picture

Adding related issue.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

This MAY need a change record lets see what committer thinks.

ressa’s picture

Assigned: ressa » Unassigned
Issue summary: View changes
Status: Reviewed & tested by the community » Postponed

I saw at the top of web/core/lib/Drupal/Component/FileSecurity/FileSecurity.php that there is a copy of this file:

/**
 * Provides file security functions.
 *
 * IMPORTANT: This file is duplicated at /composer/Plugin/VendorHardening.
 * If any change is made here, the same change should be made in the duplicate.
 * See https://www.drupal.org/project/drupal/issues/3079481

I also found the original issues, and I'll alert the subscribers of this issue in case there are good reasons to keep it at 444.