MDL-68068 core_h5p: Replace $_SESSION by $SESSION

The third-party library H5P has some references to  instead of Moodle's.
That implies that the information is not saved to backends and other issues,
so only the Moodle one should be used by core (core should be free from  and always use .).
This commit is contained in:
cescobedo
2020-03-20 07:53:30 +01:00
parent 46fe2c5533
commit dc0cbc24f3
2 changed files with 15 additions and 8 deletions
+7 -5
View File
@@ -3215,21 +3215,23 @@ class H5PCore {
* @return string
*/
private static function hashToken($action, $time_factor) {
if (!isset($_SESSION['h5p_token'])) {
global $SESSION;
if (!isset($SESSION->h5p_token)) {
// Create an unique key which is used to create action tokens for this session.
if (function_exists('random_bytes')) {
$_SESSION['h5p_token'] = base64_encode(random_bytes(15));
$SESSION->h5p_token = base64_encode(random_bytes(15));
}
else if (function_exists('openssl_random_pseudo_bytes')) {
$_SESSION['h5p_token'] = base64_encode(openssl_random_pseudo_bytes(15));
$SESSION->h5p_token = base64_encode(openssl_random_pseudo_bytes(15));
}
else {
$_SESSION['h5p_token'] = uniqid('', TRUE);
$SESSION->h5p_token = uniqid('', TRUE);
}
}
// Create hash and return
return substr(hash('md5', $action . $time_factor . $_SESSION['h5p_token']), -16, 13);
return substr(hash('md5', $action . $time_factor . $SESSION->h5p_token), -16, 13);
}
/**
+8 -3
View File
@@ -16,8 +16,7 @@ Added:
Downloaded version: 1.24 release
=== 3.8 ===
Changes:
1. In order to allow the dependency path to be overridden by child H5PCore classes, a couple of minor changes have been added to the
h5p.classes.php file:
- Into the getDependenciesFiles method, the line 2435:
@@ -44,6 +43,12 @@ and 1 ocurrence in h5p-metadata.class.php.
3. Another PR has been sent to H5P library (https://github.com/h5p/h5p-php-library/pull/69) to fix some php74 minor problems. The same fix is being applied locally by MDL-67077. Once we import a new version, if it includes de fix, this won't be needed to reapply and can be removed.
4. Replace the $_SESSION references to $SESSION. That implies that the information is saved to backends, so only the Moodle one should be used by core (core should be free from $_SESSION and always use $SESSION).
h5p.classes.php file:
- Into hashToken method:
Declare the global $SESSION.
Change all the $_SESSION by $SESSION.
A script for testing this part can be found in MDL-68068
The point 2 from above won't be needed once the mbstring extension becomes mandatory in Moodle. A request has been
sent to MDL-65809.
sent to MDL-65809.