Problem/Motivation

So everything starts here where we clone a redirect response and replace the old response.

          $safe_response = LocalRedirectResponse::createFromRedirectResponse($response);
        $event->setResponse($safe_response);

::createFromRedirectResponse takes care to copy everything, including exporting headers and sending them over, sending the path, etc. Unfortunately, cookies are not included in the constructor and despite living in the header bag, don't get exported or imported in the copy process. This means a listener that runs earlier and sets a cookie has that cookie thrown away leading to table flipping and hair pulling.

Proposed resolution

Iterate over cookies and set them on the cloned response.

Remaining tasks

Agree and commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

RC phase evaluation

Reference: https://www.drupal.org/core/d8-allowed-changes
Issue category Bug code doesn't not behave correctly.
Issue priority Normal bug. Doesn't affect core behaviors but disruptions normal assumptions about code behavior. Cookies set on a response should always be sent.
Allowed in RC Contrib blocked. Bakery commonly sets its cookies why redirecting.
Needed in RC Blocking contrib migration and site builder
No BC break, feature, etc. Just a bug.
Disruption: Fixes a bug, blocks a contributed project No disruption, just restores expected behavior.

https://www.drupal.org/node/2592479

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul created an issue. See original summary.

neclimdul’s picture

Status: Active » Needs review
FileSize
0 bytes

Did my best in the summary but hopefully this makes it a little more clear.

neclimdul’s picture

where'd the patch go d.o?

joelpittet’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Could use an automated test to ensure we don't run into this bug in the future.

The last submitted patch, 2: cookies_get_lost_during-2582309-2.patch, failed testing.

dawehner’s picture

Wow, is that something we could fix upstream?

neclimdul’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Fair enough. There where some tests for methods using this base class but not the method itself so new unit test.

Exposed a bonus SymfonyWTF: https://github.com/symfony/symfony/issues/16171

neclimdul’s picture

this one was my fault...

Status: Needs review » Needs work

The last submitted patch, 8: cookies_get_lost_during-2582309-8.patch, failed testing.

The last submitted patch, 8: cookies_get_lost_during-2582309-8.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review
FileSize
704 bytes
3.25 KB

re #6, I don't think there is a need to fix it upstream. We have this method becase we are already copying other values in this way and its an architectural issue not a bug. Possibly an architecture we could look at improving in a future release of Symfony though.

Grumble grumble groups...

Status: Needs review » Needs work

The last submitted patch, 11: cookies_get_lost_during-2582309-10.patch, failed testing.

The last submitted patch, 11: cookies_get_lost_during-2582309-10.patch, failed testing.

neclimdul’s picture

The patch that has the previous interdiff. I don't know what my problem is...

neclimdul’s picture

Status: Needs work » Needs review
Issue tags: +Contributed project blocker

Seriously? Since this was blocking my work on migrating Bakery, tagging as well.

Status: Needs review » Needs work

The last submitted patch, 14: cookies_get_lost_during-2582309-14.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review

yeah, sorry pifr. you don't get to rule my issues anymore.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thank you for adding tests! I agree, PIFR your reign is over.

tim.plunkett’s picture

Fixable on commit:

  1. +++ b/core/tests/Drupal/Tests/Component/HttpFoundation/SecuredRedirectResponseTest.php
    @@ -0,0 +1,62 @@
    +   *  {@inheritdoc}
    

    Extra space between * and {

  2. +++ b/core/tests/Drupal/Tests/Component/HttpFoundation/SecuredRedirectResponseTest.php
    @@ -0,0 +1,62 @@
    +    return true;
    

    return TRUE;

dawehner’s picture

+++ b/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php
@@ -35,6 +35,9 @@ public static function createFromRedirectResponse(RedirectResponse $response) {
     $safe_response->setProtocolVersion($response->getProtocolVersion());
     $safe_response->setCharset($response->getCharset());
+    foreach ($response->headers->getCookies() as $cookie) {
+      $safe_response->headers->setCookie($cookie);
+    }
     return $safe_response;

Can we have a comment why we are doing this here?

neclimdul’s picture

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +rc target triage

Thank you re-RTBC. Comments and docs addressed.

YesCT’s picture

@joelpittet
https://www.drupal.org/core/d8-allowed-changes
says

Non-criticals under consideration have the rc target triage tag. Issues tagged with rc target triage should have an issue summary that explains why it is important for the issue to land during RC and why it can not wait until later.

I think we need a "beta evaluation" like thing in the issue summary which goes through the criteria in https://www.drupal.org/core/d8-allowed-changes

neclimdul’s picture

Issue summary: View changes

Its my understanding the "Contributed project blocker" tag should have covered this. I'm very confused about what commiters what to see on issues right now.

neclimdul’s picture

Issue summary: View changes

Not linked from the RC evaluation but googling I found the template. Hopefully this clarifies.

YesCT’s picture

Issue summary: View changes
YesCT’s picture

neclimdul’s picture

neclimdul’s picture

Status: Reviewed & tested by the community » Needs review

Could use a look to make sure it looks right actually. Didn't mean to leave it RTBC.

joelpittet’s picture

Not sure how this will play out, I'm sure if it doesn't get in for RC it can likely go into 8.0.1 or something, but there is a fancy RC evaluation in the IS now.

+++ b/core/lib/Drupal/Component/HttpFoundation/SecuredRedirectResponse.php
@@ -46,6 +46,11 @@ public static function createFromRedirectResponse(RedirectResponse $response) {
+    // Cookies aren't are separate from other headers and have to be copied over
+    // directly.

nit: remove the word 'arn't'

joelpittet’s picture

Status: Needs review » Needs work

Would you mind posting a tests only patch with the next patch?

neclimdul’s picture

Sure thing. Hopefully I got the upload order correct...

The last submitted patch, 32: cookies_get_lost_during-2582309-32-FAILURE.patch, failed testing.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @neclimdul. I think this has all the right stuff now.

The last submitted patch, 32: cookies_get_lost_during-2582309-32-FAILURE.patch, failed testing.

xjm’s picture

Issue tags: -rc target triage +rc target

Discussed with the D8 committers and we agreed with making this an rc target.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.0.x. Thanks!

  • webchick committed 169bd2a on 8.0.x
    Issue #2582309 by neclimdul, joelpittet, YesCT, dawehner, tim.plunkett:...
neclimdul’s picture

Many thanks!

Status: Fixed » Closed (fixed)

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