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_htmlfolder containscomposer.json,composer.lock,vendor, andweb.
[...]$ 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-datauser 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
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
Comment #3
ressaAdding related issue.
Comment #4
smustgrave commentedThis MAY need a change record lets see what committer thinks.
Comment #5
ressaI saw at the top of web/core/lib/Drupal/Component/FileSecurity/FileSecurity.php that there is a copy of this file:
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.Comment #6
ressa