Problem/Motivation

We've added protection to core for https://www.drupal.org/sa-core-2018-002 and https://www.drupal.org/sa-core-2018-004 but we omitted test coverage to not give hackers any hints of how to exploit the vulnerability. However both have now been publicly exploited therefore we should add the tests so that we don't break this important functionality.

Proposed resolution

Add tests

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
6.59 KB

Here's a start from the work on tests in the security issue. I think the tests can be improved to be easier to maintain.

alexpott’s picture

Here's a rework so that you don't have to set a requests query, cookie, and request parameters all the same.

Bit of a complete re-work so no interdiff.

alexpott’s picture

Slight tweak so that all the Request object is tested together and all of the globals are tested together.

alexpott’s picture

I've used PHPUnit and Xdebug to confirm that the current test exercises 100% of the code. So at least we know every line is exercised. It would be good to confirm that all the logic is tested. Note that external destinations are not a concern because they are removed by \Drupal\Core\EventSubscriber\RedirectResponseSubscriber::sanitizeDestination(). I think though at some point we should file a follow to merge that functionality into the RequestSanitizer and also fix it. The conversion to Symfony's request introduced 2 bugs in it. Opened an issue for this #2969207: RedirectResponseSubscriber::sanitizeDestination() was upgraded from Drupal 7 incorrectly

benjy’s picture

Tests look good to me, tiny phpcs issue.

  1. +++ b/core/tests/Drupal/Tests/Core/Security/RequestSanitizerTest.php
    @@ -0,0 +1,228 @@
    +    $this->errors[] = compact("errno", "errstr");
    
    +++ b/core/tests/Drupal/Tests/Core/Security/RequestSanitizerTest.php
    @@ -0,0 +1,228 @@
    +      if ($error["errstr"] === $errstr && $error["errno"] === $errno) {
    

    Normally array keys and function args are single quotes.

alexpott’s picture

Thanks for the review @benjy. Patch attached addresses that and also a couple of other code style things.

samuel.mortenson’s picture

Nits:

  1. +++ b/core/tests/Drupal/Tests/Core/Security/RequestSanitizerTest.php
    @@ -0,0 +1,227 @@
    +  /**
    +   * @param \Symfony\Component\HttpFoundation\Request $request
    +   *   The request to sanitize.
    

    Missing comment in docblock.

  2. +++ b/core/tests/Drupal/Tests/Core/Security/RequestSanitizerTest.php
    @@ -0,0 +1,227 @@
    +    // Set up globals.
    +    $_GET = $request->query->all();
    +    $_POST = $request->request->all();
    +    $_COOKIE = $request->cookies->all();
    +    $_REQUEST = array_merge($request->cookies->all(), $request->query->all(), $request->request->all());
    +    $request->server->set('QUERY_STRING', http_build_query($request->query->all()));
    +    $_SERVER['QUERY_STRING'] = $request->server->get('QUERY_STRING');
    

    I think $request->overrideGlobals() will do this as well.

Other than that this looks like good coverage.

alexpott’s picture

Thanks for the review @samuel.mortenson

1. Fixed
2. $request->overrideGlobals() does more - it also sorts the query string. Personally I think we should do this on every request to normalise stuff for caches but that's not what we do now. One thing investigating this idea did bring up is that the test assumes the php ini var request_order is CGP but actually by default in php.ini its GP for security reasons so I've changed the test to reflect that.

samuel.mortenson’s picture

Status: Needs review » Reviewed & tested by the community

Interdiff and a re-review looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 9: 2969053-9.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

HEAD failing.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

alexpott credited Heine.

alexpott credited Jasu_M.

alexpott credited drumm.

alexpott credited larowlan.

alexpott credited mlhess.

alexpott’s picture

Adding contributors to the original issues because they all reviewed the test coverage too.

alexpott credited dawehner.

alexpott credited dsnopek.

alexpott credited pwolanin.

alexpott’s picture

Some more people.

tim.plunkett credited xjm.

tim.plunkett’s picture

  • catch committed 7c0ce17 on 8.7.x
    Issue #2969053 by alexpott, tim.plunkett, Pere Orga, cashwilliams,...

  • catch committed 36137d6 on 8.6.x
    Issue #2969053 by alexpott, tim.plunkett, Pere Orga, cashwilliams,...
catch’s picture

Version: 8.7.x-dev » 8.6.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.7.x and cherry-picked to 8.6.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.