![]() |
VOOZH | about |
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.
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).
The following diagram associates natural language concepts with specific code entities in the Maho session system.
Sources:
Mage_Core_Model_Session_Abstract definition: app/code/core/Mage/Core/Model/Session/Abstract.php31-33Maho 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
The createSessionHandler() method determines the appropriate handler based on the configuration value returned by getSessionSaveMethod().
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
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.
Maho includes a cron job core_session_clean to purge expired sessions app/code/core/Mage/Core/Model/Session.php75
_cleanFileSystemSessions() method iterates through the session directory and unlinks files older than the configured maxIdleTime app/code/core/Mage/Core/Model/Session.php86-121 The system uses file modification time (getMTime) to determine expiration app/code/core/Mage/Core/Model/Session.php133Sources:
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.
| Class | Role | Namespace |
|---|---|---|
Mage_Core_Model_Session_Abstract | Base logic, Symfony integration, and validation. | N/A |
Mage_Core_Model_Session | Generic core session and form key management. | core |
Mage_Admin_Model_Session | Admin user authentication and ACL. | admin |
Mage_Customer_Model_Session | Frontend customer state and persistence. | customer |
Mage_Api_Model_Session | API session management. | api |
Sources:
Mage_Core_Model_Session_Abstract: app/code/core/Mage/Core/Model/Session/Abstract.php31Mage_Core_Model_Session: app/code/core/Mage/Core/Model/Session.php24Mage_Admin_Model_Session: app/code/core/Mage/Admin/Model/Session.php36Mage_Customer_Model_Session: app/code/core/Mage/Customer/Model/Session.php50Mage_Api_Model_Session: app/code/core/Mage/Api/Model/Session.php19Maho performs validation on every session start to prevent hijacking.
Security settings are managed via configuration paths defined in the abstract model app/code/core/Mage/Core/Model/Session/Abstract.php49-53:
HTTP_USER_AGENT. Can be skipped via global/session/validation/http_user_agent_skip app/code/core/Mage/Core/Model/Session/Abstract.php55web/session/use_remote_addr is enabled app/code/core/Mage/Core/Model/Session/Abstract.php49web/session/use_http_x_forwarded_for is set app/code/core/Mage/Core/Model/Session/Abstract.php51The 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:
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
login($username, $password): Authenticates against the customer model app/code/core/Mage/Customer/Model/Session.php216-227setCustomerAsLoggedIn($customer): Attaches the customer object to the session and triggers renewSession() to prevent session fixation app/code/core/Mage/Customer/Model/Session.php233-237isLoggedIn(): Checks if the customer ID is present and validated against the database app/code/core/Mage/Customer/Model/Session.php190-193Sources:
Mage_Admin_Model_Session handles the administrative area.
The flow is managed by Mage_Adminhtml_IndexController:
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-155Mage_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-191setUserPasswordChanged(true) app/code/core/Mage/Admin/Model/User.php159-162Sources:
API sessions (Mage_Api_Model_Session) differ from web sessions as they are often stateless or managed via explicit session IDs.
Mage_Api_Model_User app/code/core/Mage/Api/Model/User.php237-250api/config/session_timeout configuration app/code/core/Mage/Api/Model/Session.php182-189Sources:
| Path | Description | Constant Reference |
|---|---|---|
global/session_save | Storage type (files or redis) | XML_NODE_SESSION_SAVE |
global/session_save_path | Path for file storage | XML_NODE_SESSION_SAVE_PATH |
web/cookie/cookie_lifetime | Frontend session duration | XML_PATH_COOKIE_LIFETIME |
admin/security/session_cookie_lifetime | Admin session duration | N/A |
web/session/use_remote_addr | Validate client IP | XML_PATH_USE_REMOTE_ADDR |
web/session/use_http_user_agent | Validate User Agent | XML_PATH_USE_USER_AGENT |
api/config/session_timeout | API session duration | N/A |
Sources:
Mage_Core_Model_Session_Abstract configuration nodes: app/code/core/Mage/Core/Model/Session/Abstract.php43-57Refresh this wiki