On a fresh install of 8.3.7 running on Dreamhost shared hosting, I get a warning at /admin/reports/status advising of this:

TEMPORARY FILES DIRECTORY
Not fully protected
See https://www.drupal.org/SA-CORE-2013-003 for information about the recommended .htaccess file which should be added to the /tmp directory to help protect against arbitrary code execution.

Problems:

  • The linked site is for Drupal 6 and 7. It does not provide obvious guidance for Drupal 9 and 10 users.
  • I assume we should use the .htaccess file recommended for Drupal 7. It appears I have to copy code from two separate parts of the page to get the recommended .htaccess file.
  • The warning doesn't tell me where the temp directory even is. Had I seen that, I would have immediately noticed it's using the shared /tmp for the whole server.

Expectation: warning messages link to useful pages. Unlike the page actually linked, useful pages provide clear guidance and "don't make me think" solutions. Also, the warning message here should advise me where the temp directory actual is. Don't make me hunt across the configuration to find this.

I'm filing this as a bug because I am confident that this isn't in line with Drupal's commitment to good UX.

Proposed solution

  1. Create an updated documentation page on Drupal.org that explain how to fix this problem in plain language: (done).
  2. Replace the stream wrapper temporary:// with the actual file system path. Done.
  3. Replace the link to the SA with a link to this documentation page in the warning displayed in the status report. Done.

Remaining tasks

  1. Reroll patch in #23 for Drupal 11.
  2. Address points raised in #27.
  3. Review the revised patch.
  4. After it reaches RTBC, commit to the next release.

User interface changes

Before

After

Issue fork drupal-2906490

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

Aren Cambre created an issue. See original summary.

aren cambre’s picture

Version: 8.5.x-dev » 8.3.7
cilefen’s picture

Component: configuration system » file system
Issue tags: +Documentation
gagarine’s picture

Issue tags: -UX +Usability

Usability is preferred over UX, D7UX, etc. See https://www.drupal.org/issue-tags/topic

David_Rothstein’s picture

The warning doesn't tell me where the temp directory even is.

Yes it does, it's right there in the message (in italics): "....for information about the recommended .htaccess file which should be added to the /tmp directory to help protect against...."

Is there a way to make this more clear?

I'm also linking to another issue that would make this message go away altogether in many cases, but it's definitely still worth improving the documentation here for the cases where it does need to be displayed.

David_Rothstein’s picture

Perhaps something like "... which should be added to your site's temporary files directory (located at /tmp) to help protect against..." would be better?

LinuxETC’s picture

Came across this post thanks to David Snopek (Drupal Security Team).

Recently encountered this same message on Drupal 8.8.2 after the upgrade from 8.8.1 (manually via tarball) where this issue was not noted with 8.8.1.

On a parallel system (the difference is Ubuntu versus CentOS (=issue here system) as the LAMP stack OS), this is not showing up though. I find this a bit odd and unusual since minus the OS layer, the Drupal stack, site, and modules are nearly identical.

Questions and/or feedback are welcomed. Thanks in advance.

Version: 8.3.7 » 8.3.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.3.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

frazac’s picture

Same issue here v. 8.9.3
I have a private folder outside from the web root folder, both on local and production server.
I have tried to use the drupal 7 htaccess with no results.

How to solve this error?

eliosh’s picture

The same here with drupal 9.1.9

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
gisle’s picture

Assigned: Unassigned » gisle

This persists in Drupal 9.3.3.

As for comment #5 by David_Rothstein:

Yes it does, it's right there in the message (in italics): "....for information about the recommended .htaccess file which should be added to the /tmp directory to help protect against...."

In version 9.3.3 the warning message has become:

TEMPORARY FILES DIRECTORY
Not fully protected
See https://www.drupal.org/SA-CORE-2013-003 for information about the recommended .htaccess file which should be added to the temporary:// directory to help protect against arbitrary code execution.

Notice that the path /tmp is replaced by the stream wrapper temporary://, and if you're not familiar with stream wrappers, you'll have a hard time figuring out where the temp directory is.

I think this is worth fixing. While most Drupal alumni should be able to figure it out, it is frustrating for our new community member to be hit by such unhelpful guidance when this one bites them.

So I'll have a go at fixing this core issue. My plan is:

  1. Create an updated documentation page on Drupal.org, loosely based on my replies in forum post: Error: Temporary files directory that explain how to fix this in plain language.
  2. Add a link to this documentation page in the warning displayed in the status report (I think the warning is located on line 616 in the file system.install).

Suggestions for a suitable location for this documentation page will be appreciated.

Other feedback shall also be appreciated. I won't move status to "Needs review" until I've actually done this.

gisle’s picture

I've added a documentation page about how to fix this that I hope is more up to date than SA-CORE-2013-003:

Please visit: https://www.drupal.org/docs/installing-drupal/temporary-files-directory-...

If you think it can be improved, please tell me, or Be Bold, just go ahead and improve it yourself, by pressing "Edit".

gisle’s picture

Issue summary: View changes

I also think that the stream wrapper (temporary://) is not helpful. Users want to see what directory they need to look in, '

I also think the link to the SA is not helpful. I've linked to it on the documentation page, but shall remove from the warning.

So the plan now becomes:

  1. Create an updated documentation page on Drupal.org that explain how to fix this problem in plain language.
  2. Replace the stream wrapper temporary:// with the actual file system path.
  3. Replace the link to the SA with a link to this documentation page in the warning displayed in the status report.

Added this to the issue summary under the heading "Proposed solution"

gisle’s picture

Issue summary: View changes
gisle’s picture

Assigned: gisle » Unassigned
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new2.11 KB

Uploaded patch.

Please review.

gisle’s picture

StatusFileSize
new1.81 KB

Fixed CS errors and uploaded new patch.

Please review.

gisle’s picture

Issue summary: View changes

Drupal 8 (referenced in the issue summary) is past EOL.

larowlan’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative
+++ b/core/modules/system/system.install
@@ -604,16 +604,17 @@ function system_requirements($phase) {
-          'description' => t('See <a href=":url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', [':url' => $url, '@url' => $url, '%directory' => $protected_dir->getPath()]),
+            'description' => t('See <a href=":doc">@doc</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', [':doc' => 'https://www.drupal.org/docs/installing-drupal/temporary-files-directory-not-fully-protected', '@doc' => t('this documentation page'), '%directory' => $service->getTempDirectory()]),
         ];

This message is being output for public, private and temporary (see ::defaultProtectedDirs) so I don't think to a documentation page specifically about temporary files.

Can we make that page generic enough to cover all three cases?

larowlan’s picture

Title: "TEMPORARY FILES DIRECTORY" security error provides useless guidance » "TEMPORARY/PUBLIC/PRIVATE FILES DIRECTORY" security error provides useless guidance
gisle’s picture

Status: Needs work » Needs review
StatusFileSize
new1.8 KB

I've edited the documentation page to say it is about the path to public, private and temporary directories - please see https://www.drupal.org/docs/installing-drupal/some-directory-not-fully-p... and review.

Since the title is changed, the patch has been rerolled to reflect that.

robloach’s picture

Having an .htaccess file won't help you if you're using nginx, or any other web server out there. This assumes Apache currently... Hmmm.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gisle’s picture

Issue summary: View changes

Updated issue summary to reflect status.

@RobLoach There is another issue about handling this on non-Apache: #3117665: Only show the error “Public files directory Not fully protected” for Apache servers

The current plan is to remove the warning. Not sure if that the best approach, but I'm an Apache-user. It should be sorted out by those using nginx, etc.

larowlan’s picture

Version: 9.4.x-dev » 10.1.x-dev
Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +String change in 10.1.0
+++ b/core/modules/system/system.install
@@ -604,16 +604,17 @@ function system_requirements($phase) {
-          'description' => t('See <a href=":url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', [':url' => $url, '@url' => $url, '%directory' => $protected_dir->getPath()]),
+            'description' => t('See <a href=":doc">@doc</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', [':doc' => 'https://www.drupal.org/docs/installing-drupal/some-directory-not-fully-protected', '@doc' => t('this documentation page'), '%directory' => $service->getTempDirectory()]),

* we've got a weird additional indent here
* let's just inline @doc into the translation string so the additional context is there for translators
* we're still hard-coding ::getTempDirectory for %directory, but we're in a loop at this point which is evaluating whether or not the .htaccess is in more than one place. Can we use the directory from the loop instead?

There's a string change here so this can only go into a minor.

Tagging for translators

larowlan’s picture

Priority: Normal » Minor
dqd’s picture

Testing on D 9.5.7. ....

1. Error message leads to the wrong docs and finding this issue is a question of luck. Found it by checking if it already exist or needs to be created and then by finding a link in another issue leading to here.
2. After reading thru the issue it creates the impression the correct doc link is this: https://www.drupal.org/docs/installing-drupal/some-directory-not-fully-p...
3. This doc page states that removing a possible outdated .htaccess file will make Drupal to recreate it after entering the file management settings page in admin area. This is partly true and only happens if you run cron.
4. The .htaccess file created by Drupal after that will cause the same error message again. So still not save yet? Warning level in reports is high.

Comparing the created .htaccess file with other .htaccess which do not throw errors yet, shows following difference:

git diff --git a/private-files/.htaccess b/web/sites/default/files/.htaccess
index d436879..e7f06ca 100644
--- a/private-files/.htaccess
+++ b/web/sites/default/files/.htaccess
@@ -1,13 +1,3 @@
-# Deny all requests from Apache 2.4+.
-<IfModule mod_authz_core.c>
-  Require all denied
-</IfModule>
-
-# Deny all requests from Apache 2.0-2.2.
-<IfModule !mod_authz_core.c>
-  Deny from all
-</IfModule>
-
 # Turn off all options we don't need.
 Options -Indexes -ExecCGI -Includes -MultiViews

@@ -19,9 +9,9 @@ SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
 </Files>

 # If we know how to do it safely, disable the PHP engine entirely.
-<IfModule mod_php7.c>
+<IfModule mod_php5.c>
   php_flag engine off
 </IfModule>
-<IfModule mod_php.c>
+<IfModule mod_php7.c>
   php_flag engine off
 </IfModule>
\ No newline at end of file

Which all propably needs another issue since this here is only regarding the error message doc link. It also needs to be reported there then that different server enviroments handle mod_php different. The version of mod_php(x) used can have no number if default or can have a number even if still default. (mod_php vs mod_php7) - It also depends on if the server has multiple php versions available which can be switched via update-alternatives and similar tools (useful to have old Drupal projects running not supporting php 8 yet).

dqd’s picture

Since this is a security warning I partly agree on the issue status since this issue let users run in circles with no avail. I strongly recommend to add a temporary section to the docs linked to in the warning leading to here. The warning level in the admin reports is high so it isn't just a "notification".

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gisle’s picture

Status: Needs work » Needs review

In comment #29, diqidoq objects:

This doc page states that removing a possible outdated .htaccess file will make Drupal to recreate it after entering the file management settings page in admin area. This is partly true and only happens if you run cron.

This is not my experience. I've tested it and found that:

If the directory in question is writeable by the web server, the .htaccess don't already exists, the correct one is created automatically when the site administrator visits the file system configuration page.

This is really bad UX folks. Please see this support forum post for a recent example.

Setting it back to "Needs review". If you really think it "Needs work, please list remaining tasks in the issue summary.

cilefen’s picture

A core committer commented with desired changes in #27 yet I don't see any patches since that, nor comments addressing those points.

gisle’s picture

Issue summary: View changes

Updated issue summary with current status.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work

#33 mentioned the changes that should be addressed

gisle’s picture

Issue summary: View changes

#33 doesn't mention any changes, it just refererences #27. As for #27, it mentions three changes, summarized below:

  1. we've got a weird additional indent here
  2. let's just inline @doc into the translation string so the additional context is there for translators
  3. can we use the directory from the loop instead of ::getTempDirectory for %directory?

I've no idea what is meant by the first one, so I am unable to address this.

However, items #2 and #3 look sensible.

Anyway, in the meantime, development has moved from Drupal 9 to Drupal 11, and patch in #23 no longer applies.

quietone made their first commit to this issue’s fork.

quietone’s picture

Title: "TEMPORARY/PUBLIC/PRIVATE FILES DIRECTORY" security error provides useless guidance » Link to useful information about .htaccess and directory protection
Status: Needs work » Needs review

Convert to an MR, and made changes. I hope they are useful. Also trying for a better commit message.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Opened the MR and pipeline is green.

Left 1 comment but not sure enough to warrant holding the ticket.

From what I can tell issues from #27 have been addressed, don't miss code reviews via comments at all.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Added some questions/comments.

quietone’s picture

Status: Needs work » Needs review

I updated the doc page and the displayed message.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Issue summary: View changes
StatusFileSize
new18.46 KB
new27.37 KB
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback from @longwave has been addressed here. Also seeing the same as the screenshots provided.

sivaji_ganesh_jojodae’s picture

Status: Reviewed & tested by the community » Needs work

Because of prevailing merge error.