Project

General

Profile

Actions

Bug #53034

closed

Anonymous session is not unique

Added by Thomas Schiebel about 11 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
-
Target version:
-
Start date:
2013-10-22
Due date:
% Done:

100%

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

Description

PHP 5.3.12
Apache 2.2.22 (Win32)
OS W2008R2 (also occurs in Win7)
Typo3 4.6.3

sometimes the fe_typo_user cookie contains an id which was already in use. After some researching I found out that under Window the algorithm for generating random values isn't really random

from t3lib/class.t3lib_div.php:

     
public static function generateRandomBytes($bytesToReturn) {
            // Cache 4k of the generated bytestream.
        static $bytes = '';
        $bytesToGenerate = max(4096, $bytesToReturn);

            // if we have not enough random bytes cached, we generate new ones
        if (!isset($bytes{$bytesToReturn - 1})) {
            if (TYPO3_OS === 'WIN') {
                    // Openssl seems to be deadly slow on Windows, so try to use mcrypt
                    // Windows PHP versions have a bug when using urandom source (see #24410)
                $bytes .= self::generateRandomBytesMcrypt($bytesToGenerate, MCRYPT_RAND);
            } else {
                    // Try to use native PHP functions first, precedence has openssl
                $bytes .= self::generateRandomBytesOpenSsl($bytesToGenerate);

                if (!isset($bytes{$bytesToReturn - 1})) {
                    $bytes .= self::generateRandomBytesMcrypt($bytesToGenerate, MCRYPT_DEV_URANDOM);
                }

                    // If openssl and mcrypt failed, try /dev/urandom
                if (!isset($bytes{$bytesToReturn - 1})) {
                    $bytes .= self::generateRandomBytesUrandom($bytesToGenerate);
                }
            }

                // Fall back if other random byte generation failed until now
            if (!isset($bytes{$bytesToReturn - 1})) {
                $bytes .= self::generateRandomBytesFallback($bytesToReturn);
            }
        }

            // get first $bytesToReturn and remove it from the byte cache
        $output = substr($bytes, 0, $bytesToReturn);
        $bytes = substr($bytes, $bytesToReturn);

        return $output;
    }

the function generateRandomBytesMcrypt() uses PHPs mcrypt_create_iv($size,$source). According to PHPs documentation since 5.3 it is not neccessary to call srand() anymore before calling mcrypt_create_iv() - but this does not seem to be the case if called with $source=MCRYPT_RAND. To isolate this behaviour I used the following console script (this is basically what happens under Windows):

$arr = array();
for ($i=0;$i< 10000;$i++)
{
    $arr[$i]=bin2hex(substr(mcrypt_create_iv(4096,MCRYPT_RAND),0,8));
}
print_r(array_count_values($arr));

I got serveral duplicates. However also the use of variable static $bytes does not seem to make sense as Apache seperates the static areas of its requests.

Replacing MCRYPT_RAND with MCRYPT_DEV_URANDOM t3lib/class.t3lib_div.php for windows seems to deliver unique results. Also calling srand() works.

Actions #1

Updated by Georg Ringer about 11 years ago

  • Project changed from TYPO3 Core to 1716
Actions #2

Updated by Franz G. Jahn over 10 years ago

  • OTRS-Sec Ticket-ID set to 2013102310000011
Actions #3

Updated by Helmut Hummel over 9 years ago

  • Project changed from 1716 to TYPO3 Core
  • Is Regression set to No

making this public again

Actions #4

Updated by Gerrit Code Review over 9 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40251

Actions #5

Updated by Gerrit Code Review over 9 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40251

Actions #6

Updated by Gerrit Code Review over 9 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40251

Actions #7

Updated by Gerrit Code Review over 9 years ago

Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40258

Actions #8

Updated by Helmut Hummel over 9 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #9

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF