Problem/Motivation

If I set my site to display no system error messages to end users, under some circumstances, they can still be shown due to the fact that the setting itself typically comes from the database (though it is possible to set it in settings.php) and there is a window in between setting up the drupal error handler and reading this setting from either database or cache where error messages default to being shown to end users. This seems at best inconsistent, and at worst a potential security issue, depending on what is revealed by the error message (I'd hope nothing too serious would be in those messages, but you never know). Note that this was first noticed on a D7 site, but the same happens in D8 also.

A real world example of how this can cause problems is if your error_level is set in the database rather than in settings.php, and your site uses memcache - a not too unusual setup:

  • _drupal_bootstrap_configuration sets the error handler to drupal's DSM handler. From this point until variables are initialized, any error will be shown to end users, due to the fact that the default in error_displayable is to show everything to all
  • _drupal_bootstrap_page_cache attempts to initialize variables, but ...
  • cache needs to be set up first, so cache is initialized. If this fails (memcache server is down), the error will be shown to all end users. A cache fail is not usually a catasrophic fail, so the site appears to be up, but error messages are displayed to end users, which is not what was intended if configuration has ERROR_REPORTING_HIDE
  • In fact any error up to the point that the variable is loaded from either the cache or database will be displayed to users - that's a pretty big window

If you then assume that a site using memcache might also use a caching proxy, then things get fairly nasty, as the messages in $_SESSION for anonymous users will cause your caching proxy to not cache their requests (due to the session cookie).

Here's a simple way to simulate this kind of error:

1: Set errors to hidden: https://skitch.com/e-alanevans/er335/logging-and-errors-testd8err.localhost
2: Trigger an error some point before variables are loaded (and imagine that this could be something like a memcache server being down)

diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 64872be..521d09e 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -2416,6 +2416,7 @@ function _drupal_bootstrap_variables() {
   require_once DRUPAL_ROOT . '/core/includes/lock.inc';
 
   // Load variables from the database, but do not overwrite variables set in settings.php.
+  trigger_error('TEST VARIABLES', E_USER_ERROR); // <-------- 
   $conf = variable_initialize(isset($conf) ? $conf : array());
   // Load bootstrap modules.
   require_once DRUPAL_ROOT . '/core/includes/module.inc';

3: load a page https://skitch.com/e-alanevans/er35h/welcome-to-testd8err.localhost-test...

Proposed resolution

I believe the solution is simply to set the default on displaying errors to hide them. It really depends though on whether drupal installed out of the box is considered a development setup, or a production setup. I think the safer assumption is the latter (because you can always enable error messages if you want them). At the moment, if you want to hide these error messages, you have to either do it in settings.php, which may not be practical, and may not be sufficient in extreme edge cases where an error is triggered before settings.php is available (I have no examples for this). I'll add a patch for this shortly. I think the approach needs some discussion though.

As a partial workaround you can always making sure your error_level is set in settings.php - that significantly reduces the window where errors can be displayed to end users. There is very little in the code in between setting up the error handler and loading settings from settings.php that could trigger errors (I'm sure it could be forced if you try really hard, but under normal circumstances shouldn't happen).

Remaining tasks

Determine whether the proposed solution is desired.
Review + revise.

User interface changes

If the change is accepted, error messages are assumed by default to be hidden until explicitly changed to show. Error logging should be unaffected, just the display in drupal_set_message()s.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan Evans’s picture

FileSize
1.33 KB

Possible solution attached.

Alan Evans’s picture

D7 patch would look like something like this ...

ksenzee’s picture

Status: Active » Needs review
FileSize
2.02 KB
2.19 KB

The patches in #1 and #2 look good to me but fail testing (the exception handler tests assume that exception text shows by default). Explicitly setting the variable in the exception handler tests fixes the problem, and makes more sense anyway. Attaching patches for 8.x and 7.x.

Status: Needs review » Needs work

The last submitted patch, 1671318-3.hide-errors.patch, failed testing.

ksenzee’s picture

Status: Needs work » Needs review
FileSize
2.95 KB
2.6 KB

Oops, missed a failing test.

jams1988’s picture

#5: 1671318-5.hide-errors.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1671318-5.hide-errors.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.

pwolanin’s picture

Issue summary: View changes
Issue tags: +Needs backport to D7, +Needs reroll
reszli’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.88 KB

Rerolled for D8.

Status: Needs review » Needs work

The last submitted patch, 9: 1671318-9.patch, failed testing.

reszli’s picture

Status: Needs work » Needs review
FileSize
2.35 KB
1.76 KB

Fixed error introduced by the old patch in another file.

reszli’s picture

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
rpayanm’s picture

Status: Needs work » Needs review
FileSize
2.25 KB
jhedstrom’s picture

From what I can tell, the actual fix in #5 got lost from #11 on, and all that remains is a test that is passing without the change in error handling.

pwieck’s picture

Issue tags: -Needs reroll

mgifford queued 14: 1671318-14.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 14: 1671318-14.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

David_Rothstein’s picture

Linking to an issue that I thought this issue might solve, but looking at the patch here it's actually something different.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

dkre’s picture

I ran into this bug with Swiftmailer library creating the error (a notice) which Drupal then displayed on 8.2.4.

The error_level being reported within function _drupal_get_error_level() is 'verbose' while my settings are 'none' (or ERROR_REPORTING_HIDE / 'hide') within admin/config/development/logging. I'm not sure that's helpful but I couldn't make sense of how this is being defined.

For anyone looking for a workaround the only option is to hack core - but it does prevent ugly backtraced error messages being displayed on your production site.

Add the lines with + at the start:

/Core/Includes/errors.inc

Line 230:

+$uid = \Drupal::currentUser()->id();
+if($uid == '1'){</strong>

if ($error_level != ERROR_REPORTING_DISPLAY_VERBOSE) {
 // ...
  $message = SafeMarkup::format('%type: @message in %function (line %line of %file).', $error);
  }
  else {
   // ...
    $error['@backtrace'] = Error::formatBacktrace($backtrace);
     $message = SafeMarkup::format('%type: @message in %function (line %line of %file). <pre    class="backtrace">@backtrace</pre>', $error);
  }


+}

This will only display these errors to the administrator account.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

Version: 8.8.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. 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.

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

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.

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

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

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

Checking in on the issue that has not had discussion for 7 years.

Is this still relevant to Drupal 10?

Since we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

Thanks!