Skip to content

Commit ba97eda

Browse files
authored
Merge pull request #2821 from chamilo/fix-unserialize
Improve `unserialize` security
2 parents a792ca1 + 102c1b7 commit ba97eda

27 files changed

+207
-40
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112
"knplabs/knp-components": "~1.3",
113113
"guzzlehttp/guzzle": "~6.0",
114114
"onelogin/php-saml": "^3.0",
115-
"symfony/dom-crawler": "~3.4"
115+
"symfony/dom-crawler": "~3.4",
116+
"brumann/polyfill-unserialize": "^1.0"
116117
},
117118
"require-dev": {
118119
"behat/behat": "@stable",

main/admin/career_diagram.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
ALTER TABLE extra_field_values modify column value longtext null;
1515
*/
1616

17+
use Fhaculty\Graph\Graph;
18+
1719
$cidReset = true;
1820
require_once __DIR__.'/../inc/global.inc.php';
1921

@@ -106,7 +108,8 @@
106108
$tpl = new Template(get_lang('Diagram'));
107109
$html = Display::page_subheader2($careerInfo['name'].$urlToString);
108110
if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
109-
$graph = unserialize($item['value']);
111+
/** @var Graph $graph */
112+
$graph = api_unserialize_content('career', $item['value']);
110113
$html .= Career::renderDiagramByColumn($graph, $tpl);
111114
} else {
112115
Display::addFlash(

main/admin/gradebook_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188

189189
$options = [];
190190
if (!empty($categoryData['depends'])) {
191-
$list = unserialize($categoryData['depends']);
191+
$list = api_unserialize_content('not_allowed_classes', $categoryData['depends']);
192192
foreach ($list as $itemId) {
193193
$courseInfo = api_get_course_info_by_id($itemId);
194194
$options[$itemId] = $courseInfo['name'];

main/auth/sso/sso.Drupal.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ public function generateProfileEditingURL($userId = 0, $asAdmin = false)
293293
*/
294294
private function decode_cookie($cookie)
295295
{
296-
return unserialize(base64_decode($cookie));
296+
return api_unserialize_content(
297+
'not_allowed_classes',
298+
base64_decode($cookie)
299+
);
297300
}
298301
}

main/auth/sso/sso.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ public function generateProfileEditingURL($userId = 0, $asAdmin = false)
296296
*/
297297
private function decode_cookie($cookie)
298298
{
299-
return unserialize(base64_decode($cookie));
299+
return api_unserialize_content(
300+
'not_allowed_classes',
301+
base64_decode($cookie)
302+
);
300303
}
301304
}

main/course_home/course_home.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* For licensing terms, see /license.txt */
33

44
use ChamiloSession as Session;
5+
use Fhaculty\Graph\Graph;
56

67
/**
78
* HOME PAGE FOR EACH COURSE.
@@ -392,7 +393,11 @@
392393
);
393394

394395
if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
395-
$graph = unserialize($item['value']);
396+
/** @var Graph $graph */
397+
$graph = api_unserialize_content(
398+
'career',
399+
$item['value']
400+
);
396401
$diagram = Career::renderDiagram($careerInfo, $graph);
397402
}
398403
}

main/exercise/hotspot_admin.inc.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
$objAnswer = new Answer($questionId);
5757
}
5858

59-
$color = unserialize($color);
60-
$reponse = unserialize($reponse);
61-
$comment = unserialize($comment);
62-
$weighting = unserialize($weighting);
63-
$hotspot_coordinates = unserialize($hotspot_coordinates);
64-
$hotspot_type = unserialize($hotspot_type);
65-
$destination = unserialize($destination);
59+
$color = api_unserialize_content('not_allowed_classes', $color);
60+
$reponse = api_unserialize_content('not_allowed_classes', $reponse);
61+
$comment = api_unserialize_content('not_allowed_classes', $comment);
62+
$weighting = api_unserialize_content('not_allowed_classes', $weighting);
63+
$hotspot_coordinates = api_unserialize_content('not_allowed_classes', $hotspot_coordinates);
64+
$hotspot_type = api_unserialize_content('not_allowed_classes', $hotspot_type);
65+
$destination = api_unserialize_content('not_allowed_classes', $destination);
6666
unset($buttonBack);
6767
}
6868

main/exercise/question.class.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,10 @@ public function search_engine_edit(
11451145
$se_doc = $di->get_document((int) $se_ref['search_did']);
11461146
if ($se_doc !== false) {
11471147
if (($se_doc_data = $di->get_document_data($se_doc)) !== false) {
1148-
$se_doc_data = unserialize($se_doc_data);
1148+
$se_doc_data = api_unserialize_content(
1149+
'not_allowed_classes',
1150+
$se_doc_data
1151+
);
11491152
if (isset($se_doc_data[SE_DATA]['type']) &&
11501153
$se_doc_data[SE_DATA]['type'] == SE_DOCTYPE_EXERCISE_QUESTION
11511154
) {

main/exercise/upload_exercise.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ function lp_upload_quiz_action_handling()
548548
$lpObject = Session::read('lpobject');
549549

550550
if (!empty($lpObject)) {
551-
$oLP = unserialize($lpObject);
551+
/** @var learnpath $oLP */
552+
$oLP = api_unserialize_content('lp', $lpObject);
552553
if (is_object($oLP)) {
553554
if ((empty($oLP->cc)) || $oLP->cc != api_get_course_id()) {
554555
$oLP = null;

main/extra/upgrade_school_calendar.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* For licensing terms, see /license.txt */
33

44
// not used??
5+
56
exit;
67

78
require_once '../inc/global.inc.php';
@@ -28,6 +29,11 @@
2829
$d_number = (int) $d_number;
2930
$sql4 = "UPDATE set_module SET cal_day_num = $d_number WHERE id = $d_id ";
3031
Database::query($sql4);
31-
print_r(unserialize(Security::remove_XSS($_POST['aaa'])));
32+
print_r(
33+
api_unserialize_content(
34+
'not_allowed_classes',
35+
Security::remove_XSS($_POST['aaa'])
36+
)
37+
);
3238

3339
Display::display_footer();

0 commit comments

Comments
 (0)