Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento\Customer\Model\Account\Redirect::setRedirectCookie() not properly working #24547

Closed
nikoskip opened this issue Sep 11, 2019 · 7 comments
Assignees
Labels
Component: Cookie Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@nikoskip
Copy link

nikoskip commented Sep 11, 2019

Preconditions (*)

  1. Magento 2.3.2

Steps to reproduce (*)

Call method Magento\Customer\Model\Account\Redirect::setRedirectCookie()

$this->accountRedirect->setRedirectCookie($this->urlBuilder->getUrl('checkout'));

Expected result (*)

Cookie login_redirect created

Actual result (*)

The cookie is sent to the browser, but not properly. All the cookie params are missing.

image

Additional information

I checked the code and the problem is that the method setPublicCookie needs to include a PublicCookieMetadata instance as third param.

<?php
// vendor/magento/module-customer/Model/Account/Redirect.php:280
/**
     * Save redirect route to cookie for case of successful login/registration
     *
     * @param string $route
     * @return void
     */
    public function setRedirectCookie($route)
    {
        $this->getCookieManager()->setPublicCookie(self::LOGIN_REDIRECT_URL, $route);
    }

Indeed maybe setPublicCookie should require $metadata as mandatory. Why someone would need to create a cookie without params?

@m2-assistant
Copy link

m2-assistant bot commented Sep 11, 2019

Hi @nikoskip. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@nikoskip do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Sep 11, 2019
@engcom-Charlie engcom-Charlie self-assigned this Sep 11, 2019
@m2-assistant
Copy link

m2-assistant bot commented Sep 11, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@ralphgarrison
Copy link

ralphgarrison commented Sep 11, 2019 via email

@engcom-Charlie engcom-Charlie added Component: Cookie Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Sep 11, 2019
@ghost ghost unassigned engcom-Charlie Sep 11, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-20107 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Sep 11, 2019
@nikoskip
Copy link
Author

BTW, the clearRedirectCookie is not working either. You also need to configure the cookie params to properly delete it.

I had to override this methods to get this to working. Here is my code if someone needs it, hope it helps!

<?php
    /**
     * @param string $route
     * @return void
     */
    public function setRedirectCookie($route)
    {
        $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
        $metadata->setPath($this->sessionConfig->getCookiePath());
        $metadata->setDomain($this->sessionConfig->getCookieDomain());
        $metadata->setSecure($this->sessionConfig->getCookieSecure());
        $metadata->setHttpOnly($this->sessionConfig->getCookieHttpOnly());
        $metadata->setDuration($this->sessionConfig->getCookieLifetime());

        $this->getCookieManager()->setPublicCookie(self::LOGIN_REDIRECT_URL, $route, $metadata);
    }

    /**
     * @throws \Magento\Framework\Exception\InputException
     * @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException
     */
    public function clearRedirectCookie()
    {
        $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
        $metadata->setPath($this->sessionConfig->getCookiePath());
        $metadata->setDomain($this->sessionConfig->getCookieDomain());

        $this->getCookieManager()->deleteCookie(self::LOGIN_REDIRECT_URL, $metadata);
    }

@sashas777 sashas777 self-assigned this Sep 15, 2019
@m2-assistant
Copy link

m2-assistant bot commented Sep 15, 2019

Hi @sashas777. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


sashas777 added a commit to sashas777/magento2 that referenced this issue Sep 15, 2019
sashas777 added a commit to sashas777/magento2 that referenced this issue Sep 18, 2019
…ct::setRedirectCookie() not properly working
@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Feb 20, 2020
magento-engcom-team added a commit that referenced this issue Feb 20, 2020
…Redirect::setRedirectCookie() not properly working #24612

 - Merge Pull Request #24612 from sashas777/magento2:issue-24547
 - Merged commits:
   1. a15f335
   2. 664056f
   3. 5188efd
   4. 3cf8f22
   5. 7597003
   6. 9413892
   7. 9f2bbc2
   8. bfa636f
   9. 6446aed
   10. 162ca60
   11. 16da706
   12. 2c24ef9
   13. a514803
   14. bfeadd7
   15. cd5ef3c
   16. dc416a9
   17. 41ce59e
   18. f021f1e
   19. 511e16a
magento-engcom-team pushed a commit that referenced this issue Feb 20, 2020
…Redirect::setRedirectCookie() not properly working #24612
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Cookie Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

5 participants