VOOZH about

URL: https://deepwiki.com/MahoCommerce/maho/5.3-session-management

⇱ Session Management | MahoCommerce/maho | DeepWiki


Loading...
Last indexed: 15 May 2026 (ea8ab8)
Menu

Session Management

Purpose and Scope

This document details the session management system in Maho, which has been modernized to utilize Symfony HttpFoundation for session handling while maintaining the legacy Maho/Magento model interface. It covers session storage (Files and Redis), validation logic, security options, and the implementation of customer and admin sessions. For authentication mechanisms, see Security and Authentication.

Session Architecture Overview

Maho's session architecture bridges the legacy Mage_Core_Model_Session_Abstract interface with a Symfony-based backend. This provides a robust foundation for session storage and lifecycle management. The system uses a shared Symfony Session instance stored in the Maho registry to ensure consistency across different session namespaces (e.g., frontend, adminhtml).

Code-to-Entity Mapping

The following diagram associates natural language concepts with specific code entities in the Maho session system.


Sources:

Session Storage Configuration

Maho supports two primary session storage handlers: Native Files and Redis. The selection is determined by the global/session_save configuration node app/code/core/Mage/Core/Model/Session/Abstract.php46

Storage Initialization Flow

The createSessionHandler() method determines the appropriate handler based on the configuration value returned by getSessionSaveMethod().


Redis Storage

Maho uses the RedisSessionHandler from Symfony app/code/core/Mage/Core/Model/Session/Abstract.php17 It requires a DSN configured in global/redis_session/dsn (e.g., redis://[password@]host[:port][/database]) app/code/core/Mage/Core/Model/Session/Abstract.php147-150 If the DSN is missing, the system throws an exception during initialization. The handler is initialized using RedisAdapter::createConnection($dsn) app/code/core/Mage/Core/Model/Session/Abstract.php159

File Storage

Uses NativeFileSessionHandler app/code/core/Mage/Core/Model/Session/Abstract.php16 pointing to the path defined in global/session_save_path app/code/core/Mage/Core/Model/Session/Abstract.php47 or the default system temporary directory.

Session Cleanup

Maho includes a cron job core_session_clean to purge expired sessions app/code/core/Mage/Core/Model/Session.php75

Sources:

Session Models and Hierarchy

All session models inherit from Mage_Core_Model_Session_Abstract, which wraps the Symfony session object. This abstraction allows Maho to manage messages, validation data, and specific domain logic.

ClassRoleNamespace
Mage_Core_Model_Session_AbstractBase logic, Symfony integration, and validation.N/A
Mage_Core_Model_SessionGeneric core session and form key management.core
Mage_Admin_Model_SessionAdmin user authentication and ACL.admin
Mage_Customer_Model_SessionFrontend customer state and persistence.customer
Mage_Api_Model_SessionAPI session management.api

Sources:

Session Validation and Security

Maho performs validation on every session start to prevent hijacking.

Validation Criteria

Security settings are managed via configuration paths defined in the abstract model app/code/core/Mage/Core/Model/Session/Abstract.php49-53:

  1. User Agent: Compares HTTP_USER_AGENT. Can be skipped via global/session/validation/http_user_agent_skip app/code/core/Mage/Core/Model/Session/Abstract.php55
  2. Remote Address: Validates client IP if web/session/use_remote_addr is enabled app/code/core/Mage/Core/Model/Session/Abstract.php49
  3. X-Forwarded-For: Validates forwarding headers if web/session/use_http_x_forwarded_for is set app/code/core/Mage/Core/Model/Session/Abstract.php51

Form Key Protection

The Mage_Core_Model_Session class provides getFormKey() and validateFormKey($formKey) to prevent CSRF attacks app/code/core/Mage/Core/Model/Session.php40-65 A 16-character random string is generated and stored in the session app/code/core/Mage/Core/Model/Session.php53

Sources:

Customer Sessions

The Mage_Customer_Model_Session manages the logged-in customer state. It determines its namespace based on the website scope configuration app/code/core/Mage/Customer/Model/Session.php78-83

Authentication Logic

Code-to-Entity Mapping (Customer)


Sources:

Admin Sessions

Mage_Admin_Model_Session handles the administrative area.

Admin Login Process

The flow is managed by Mage_Adminhtml_IndexController:

  1. Pre-login: preloginAction checks credentials and handles 2FA requirements app/code/core/Mage/Adminhtml/controllers/IndexController.php51-71 This calls Mage_Admin_Model_Session::prelogin() which triggers user authentication and flags if 2FA is needed app/code/core/Mage/Admin/Model/Session.php140-155
  2. Login: Mage_Admin_Model_Session::login() authenticates the user via Mage_Admin_Model_User, calls renewSession(), and initializes the ACL app/code/core/Mage/Admin/Model/Session.php161-191
  3. Startup: Users are redirected to their profile-specific startup page app/code/core/Mage/Adminhtml/controllers/IndexController.php40-41

Admin Session Security

Sources:

API Sessions

API sessions (Mage_Api_Model_Session) differ from web sessions as they are often stateless or managed via explicit session IDs.

Sources:

Configuration Reference

PathDescriptionConstant Reference
global/session_saveStorage type (files or redis)XML_NODE_SESSION_SAVE
global/session_save_pathPath for file storageXML_NODE_SESSION_SAVE_PATH
web/cookie/cookie_lifetimeFrontend session durationXML_PATH_COOKIE_LIFETIME
admin/security/session_cookie_lifetimeAdmin session durationN/A
web/session/use_remote_addrValidate client IPXML_PATH_USE_REMOTE_ADDR
web/session/use_http_user_agentValidate User AgentXML_PATH_USE_USER_AGENT
api/config/session_timeoutAPI session durationN/A

Sources: