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

Backend throws PHP Fatal TypeError when session storage is empty #34531

Closed
pmzandbergen opened this issue Nov 4, 2021 · 14 comments · Fixed by #34514
Closed

Backend throws PHP Fatal TypeError when session storage is empty #34531

pmzandbergen opened this issue Nov 4, 2021 · 14 comments · Fixed by #34514
Assignees
Labels
Area: Security Component: Security Issue: ready for confirmation Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.3-p1 Indicates original Magento version for the Issue report. Severity: S1 Affects critical data or functionality and forces users to employ a workaround.

Comments

@pmzandbergen
Copy link
Contributor

pmzandbergen commented Nov 4, 2021

Description
When the admin session storage is empty, a PHP Fatal TypeError occurs:

PHP Fatal error:  Uncaught TypeError: strtotime() expects parameter 1 to be string, null given in .../vendor/magento/module-security/Model/AdminSessionInfo.php:136
Stack trace:
#0 .../vendor/magento/module-security/Model/AdminSessionInfo.php(136): strtotime(NULL)
#1 .../vendor/magento/module-security/Model/AdminSessionInfo.php(119): Magento\Security\Model\AdminSessionInfo->isSessionExpired()
#2 .../vendor/magento/module-security/Model/AdminSessionInfo.php(108): Magento\Security\Model\AdminSessionInfo->checkActivity()
#3 .../vendor/magento/module-security/Model/Plugin/AuthSession.php(63): Magento\Security\Model\AdminSessionInfo->isLoggedInStatus()
#4 .../vendor/magento in .../vendor/magento/module-security/Model/AdminSessionInfo.php on line 136

Please note that line numbers might be different in the current version, the problem however still exists.

Since
Introduced with MC-34197:
67fae82
Specific:

$sessionUser = $this->getUser();

Suggested Fix
Return true if the session is blank:
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Security/Model/AdminSessionInfo.php#L130

    public function isSessionExpired()
    {
        $lifetime = $this->securityConfig->getAdminSessionLifetime();
        $currentTime = $this->dateTime->gmtTimestamp();
        $lastUpdatedTime = $this->getUpdatedAt();
        if (empty($lastUpdatedTime)) {
            return true;
        }
        if (!is_numeric($lastUpdatedTime)) {
            $lastUpdatedTime = strtotime($lastUpdatedTime);
        }

        return $lastUpdatedTime <= ($currentTime - $lifetime) ? true : false;
    }
@m2-assistant
Copy link

m2-assistant bot commented Nov 4, 2021

Hi @pmzandbergen. Thank you for your report.
To speed up processing of this issue, make sure that you provided the following information:

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

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

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

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@simonmaass
Copy link

related... #34415

@ihor-sviziev ihor-sviziev added Reported on 2.4.3-p1 Indicates original Magento version for the Issue report. Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. labels Nov 5, 2021
@ihor-sviziev ihor-sviziev added Area: Security Component: Security Severity: S1 Affects critical data or functionality and forces users to employ a workaround. and removed Progress: ready for dev labels Nov 5, 2021
@kanevbg
Copy link

kanevbg commented Mar 21, 2022

Magento version 2.3.7-p2 has the same issue.

@albsa
Copy link

albsa commented Apr 8, 2022

@kanevbg did you find any solution for it?

1 similar comment
@albsa
Copy link

albsa commented Apr 8, 2022

@kanevbg did you find any solution for it?

@kanhaiya5590
Copy link
Contributor

kanhaiya5590 commented Apr 8, 2022

Hi @albsa and @kanevbg,

https://github.com/magento/magento2/pull/34606/files

If want to quick soluton then update

  1. app/code/Magento/Security/Model/AdminSessionInfo.php
  2. app/code/Magento/Security/Model/AdminSessionsManager.php

files logic in respective place or create a patch file and apply.

do have look on solution which added for 2.3.7 version, logic is same/similar like 2.4.x

@kanevbg
Copy link

kanevbg commented Apr 8, 2022

@albsa since than I created patch and already using on production. Let me help you
HD-MDVA-42269-1.zip

@albsa
Copy link

albsa commented Apr 8, 2022

@kanhaiya5590 i tried multiple times yesterdya with that patch, but composer kept failing with applying the patch. @kanevbg I am trying your hotfix right now, hoping it works.

@albsa
Copy link

albsa commented Apr 8, 2022

@kanhaiya5590 @kanevbg Now I keep getting that the You current session has expired when signing in. Cleared cache, history cookies, etc. Did you guys also had this issue?

@albsa
Copy link

albsa commented Apr 8, 2022

@kanhaiya5590 @kanevbg Now I keep getting that the You current session has expired when signing in. Cleared cache, history cookies, etc. Did you guys also had this issue?

@albsa
Copy link

albsa commented Apr 12, 2022

For other people regarding this matter, if you applied this patch and still can't login, we had this issue https://magento.stackexchange.com/questions/353147/can-we-increase-the-system-security-session-size-at-admin-on-magento-2

[2022-04-12 13:11:50] report.WARNING: Session size of 489033 exceeded allowed session max size of 400000.

Solved it by running this command on CLI bin/magento config:set system/security/max_session_size_admin 800000

1 similar comment
@albsa
Copy link

albsa commented Apr 12, 2022

For other people regarding this matter, if you applied this patch and still can't login, we had this issue https://magento.stackexchange.com/questions/353147/can-we-increase-the-system-security-session-size-at-admin-on-magento-2

[2022-04-12 13:11:50] report.WARNING: Session size of 489033 exceeded allowed session max size of 400000.

Solved it by running this command on CLI bin/magento config:set system/security/max_session_size_admin 800000

@tthierryEra
Copy link

This issue happens when I change my database and I had an active session. Clearing my cooke and re-login in solved this.

@theiconnz
Copy link

Clear the cookies, and try again. It worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Security Component: Security Issue: ready for confirmation Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: done Reported on 2.4.3-p1 Indicates original Magento version for the Issue report. Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
Archived in project
8 participants