Project

General

Profile

Actions

Bug #90744

closed

RedisSessionBackend throws exception if session data empty or cannot be decoded

Added by Matthias Krams over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2020-03-12
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

The RedisSessionBackend (typo3/sysext/core/Classes/Session/Backend/RedisSessionBackend.php) throws an error if the data stored in Redis cannot be decoded. There is a bug in the get method. An array is expected as return value. But if the function "json_decode" returns null, TYPO3 throws the error: "Core: Exception handler (WEB): Uncaught TYPO3 Exception: Return value of TYPO3\CMS\Core\Session\Backend\RedisSessionBackend::get() must be of the type array, null returned".

Current

/**
     * Read session data
     *
     * @param string $sessionId
     * @return array Returns the session data
     * @throws SessionNotFoundException
     */
    public function get(string $sessionId): array
    {
        $this->initializeConnection();

        $key = $this->getSessionKeyName($sessionId);
        $rawData = $this->redis->get($key);

        if ($rawData !== false) {
            return json_decode(
                $rawData,
                true
            );
        }
        throw new SessionNotFoundException('Session could not be fetched from redis', 1481885583);
    }

Fix

/**
     * Read session data
     *
     * @param string $sessionId
     * @return array Returns the session data
     * @throws SessionNotFoundException
     */
    public function get(string $sessionId): array
    {
        $this->initializeConnection();

        $key = $this->getSessionKeyName($sessionId);
        $rawData = $this->redis->get($key);

        if ($rawData !== false) {
            $sessionData = json_decode(
                $rawData,
                true
            );

            if(!is_null($sessionData)) {
                return $sessionData;
            }
        }
        throw new SessionNotFoundException('Session could not be fetched from redis', 1481885583);
    }
Actions

Also available in: Atom PDF