Magento 2 Admin Sessions: Unpacking a Hidden Session Fixation Risk

For Magento 2 users, developers, and merchants, understanding platform security is paramount. A GitHub issue (Issue #41872) recently highlighted a "hardening issue" concerning admin session management in Magento 2.4.x, specifically a form of session fixation (CWE-384).

Magento 2 Admin Sessions: Unpacking a Hidden Session Fixation Risk

The issue, reported by lbajsarowicz, details how a pre-login admin session ID can remain authenticated even after a successful administrator login. This means an old, seemingly discarded session ID could still grant access to the admin dashboard.

The Core Problem: Persistent Pre-Login Session IDs

The vulnerability can be reproduced:

  • Step 1: Access /admin/ and note the initial admin cookie (OLD).
  • Step 2: Log in as an administrator, setting a new admin cookie (NEW).
  • Step 3: From a different client, request /admin/admin/dashboard/ sending only Cookie: admin=OLD.

The expected result is a login form; the pre-login session ID should be invalidated. However, the actual result shows the second client gaining dashboard access. Both OLD and NEW session IDs remain authenticated, with OLD valid until expiration.

Technical Deep Dive: Why This Happens

The root cause lies in Magento\Backend\Model\Auth::login()'s operation sequence. It first stores the user via setUser(), then calls Auth\Session::processLogin(), which triggers SessionManager::regenerateId().

Crucially, SessionManager::regenerateId() invokes PHP's native session_regenerate_id() without arguments, meaning delete_old_session = false. Consequently, PHP writes the current $_SESSION data (containing the authenticated user) under the old session ID before switching. This leaves the old session ID authenticated.

Notably, Customer\Model\Session::setCustomerDataAsLoggedIn() correctly regenerates the ID before storing customer data, avoiding this issue for customer logins.

Severity, Context, and Community Insights

Triaged as S2, this issue was deemed "informative" by Adobe's bug bounty and "not a vulnerability" by Intigriti. Exploitation requires a separate method to "plant" a known admin cookie. Despite this, it's a "hardening issue" as session ID regeneration on login should invalidate pre-existing IDs.

Implications for Magento Merchants and Developers

For merchants, this highlights the need for multi-layered security and timely updates. Any weakness in session management is a potential vulnerability. For developers, it's a valuable lesson in secure coding: the precise identification of the code logic (Auth::login()'s order and session_regenerate_id()'s default) offers clear insight into preventing such issues and the importance of explicit session regeneration.

Shopping Mover's Takeaway

At Shopping Mover, robust security is paramount for e-commerce platforms. This GitHub insight underscores that subtle logical flaws in core functionality can have significant security implications. Staying informed, understanding technical underpinnings, and applying best practices are vital for a secure Magento environment.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools