Skip to content

Fix \Magento\Checkout\Controller\Index\Index::isSecureRequest method to take care of current request being secure and also from referer, as stated in phpdoc block#14428

Merged
magento-engcom-team merged 1 commit intomagento:2.2-developfrom
adrian-martinez-interactiv4:FR22#REMOVE-REGENERATE-SESSION-ID-CHECKOUT-CONTROLLER
May 12, 2018
Merged

Conversation

@adrian-martinez-interactiv4
Copy link
Copy Markdown
Contributor

@adrian-martinez-interactiv4 adrian-martinez-interactiv4 commented Mar 28, 2018

Description

Fix \Magento\Checkout\Controller\Index\Index::isSecureRequest method to take care of current request being secure and also from referer, as stated in phpdoc block.

After last try to implement a solution for session loss in checkout, this private method did behaviour as expected. Updated as agreed with @sidolov .

Fixed Issues (if relevant)

  1. Hit fast twice F5 on checout page, customer loggs out automatically #4301: Hit fast twice F5 on checout page, customer loggs out automatically
  2. Concurrent (quick reload) requests on checkout cause cart to empty - related to session_regenerate_id #12362: Concurrent (quick reload) requests on checkout cause cart to empty - related to session_regenerate_id
  3. [2.1.11] Add to cart, try to checkout, cart is empty but mini-cart has items. #13427: Add to cart, try to checkout, cart is empty but mini-cart has items.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@sidolov
Copy link
Copy Markdown
Contributor

sidolov commented Mar 29, 2018

Hi @adrian-martinez-interactiv4 , regenerate_session_id call was added in order to prevent session fixation attacks. Atack possible when browsing between secure and insecure pages. We can’t remove the line in question as it may theoretically compromise security.

We have the story for implementation secure cookies and session transfer mechanism.

For now, I propose to leave a comment under the line with regenerate_session_id call with an explanation why it was added.

@magento-engcom-team magento-engcom-team added this to the March 2018 milestone Mar 29, 2018
@magento-engcom-team magento-engcom-team added Release Line: 2.2 partners-contribution Pull Request is created by Magento Partner Partner: Interactiv4 Pull Request is created by partner Interactiv4 labels Mar 29, 2018
@adrian-martinez-interactiv4
Copy link
Copy Markdown
Contributor Author

Hi @sidolov , I've read https://www.owasp.org/index.php/Session_fixation article and I think I have understood what it says about session hijacking, but I have some questions about this all.

  • Assuming browsing between secure and insecure pages is possible due to configuration, wouldn't this be a problem also for /customer/account section? I mean, why isn't renewed session id when accessing customer account, if session id could have been hijacked ?

  • Secure cookies have been already implemented for secure requests when configuration does not allow mixed navigation. Looking at \Magento\Framework\Session\Config::__construct:

    $secureURL = $this->_scopeConfig->getValue('web/secure/base_url', $this->_scopeType);
    $unsecureURL = $this->_scopeConfig->getValue('web/unsecure/base_url', $this->_scopeType);
    $isFullySecuredURL = $secureURL == $unsecureURL;
    $this->setCookieSecure($isFullySecuredURL && $this->_httpRequest->isSecure());
    

    If request is secure and base secure and unsecure urls match, secure cookies are set, and travel encrypted. I wonder if regenerating session id in controller index could be limited to unsecure cookies, denoting mixed/unsecured navigation. This at least would skip the issue for fully secured pages.

    This would be some pseudo-code (objectManager used only for example purpose):

    if(!$this->_objectManager->get(\Magento\Framework\Session\Config::class)->getCookieSecure()) {
        $this->_customerSession->regenerateId();
    }
    
  • Since the problem is the time between session has been regenerated and the browser acknowledging the change and updating its cookie, I'm also wondering if session regeneration could be moved just before the response is sent (maybe tied to controller_front_send_response_before event or similar), to reduce this issue as possible.

I'll be looking forward for your comments, thank you in advance.

@sidolov
Copy link
Copy Markdown
Contributor

sidolov commented Apr 16, 2018

Hi @adrian-martinez-interactiv4 , thanks for your investigation!

Good point for the case with fully secured pages, I agree that would be better check and skip regenerateId method call.

Regarding customer/account section - session id regenerated in several scenarios with account manipulation, for example:

I think moving session regeneration call to controller_front_send_response_before event may not completely change the situation, we need a complex solution for all cases.

…to take care of current request being secure and also from referer, as stated in phpdoc block
@adrian-martinez-interactiv4 adrian-martinez-interactiv4 force-pushed the FR22#REMOVE-REGENERATE-SESSION-ID-CHECKOUT-CONTROLLER branch from f4435fd to dc687c6 Compare May 8, 2018 16:51
@adrian-martinez-interactiv4 adrian-martinez-interactiv4 changed the title Remove regenerate session id in \Magento\Checkout\Controller\Index\Index Fix \Magento\Checkout\Controller\Index\Index::isSecureRequest method to take care of current request being secure and also from referer, as stated in phpdoc block May 8, 2018
@adrian-martinez-interactiv4
Copy link
Copy Markdown
Contributor Author

Updated PR as agreed with @sidolov after last changes.

@magento-engcom-team
Copy link
Copy Markdown
Contributor

Hi @adrian-martinez-interactiv4. Thank you for your contribution.
Changes from your Pull Request will be available with the upcoming 2.2.5 release.

@southerncomputer
Copy link
Copy Markdown
Contributor

Where should we file CVE for relying on referer from client browser for issecure patch?

Pretty blatant security issue , yes?

@adrian-martinez-interactiv4 adrian-martinez-interactiv4 deleted the FR22#REMOVE-REGENERATE-SESSION-ID-CHECKOUT-CONTROLLER branch May 16, 2018 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Partner: Interactiv4 Pull Request is created by partner Interactiv4 partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants