Skip to content

Commit 0de8470

Browse files
committed
Security fix #2532
- Use json_decode/json_encode instead base64 - Add Security::remove_XSSS
1 parent 9076126 commit 0de8470

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

main/inc/lib/webservices/Rest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,16 +823,9 @@ public function getCourseLearnPaths()
823823
*/
824824
public static function decodeParams($encoded)
825825
{
826-
$decoded = str_replace(['-', '_', '.'], ['+', '/', '='], $encoded);
827-
$mod4 = strlen($decoded) % 4;
826+
$decoded = json_decode($encoded);
828827

829-
if ($mod4) {
830-
$decoded .= substr('====', $mod4);
831-
}
832-
833-
$b64Decoded = base64_decode($decoded);
834-
835-
return unserialize($b64Decoded);
828+
return $decoded;
836829
}
837830

838831
/**
@@ -1319,10 +1312,8 @@ private function encodeParams(array $additionalParams = [])
13191312
'api_key' => $this->apiKey,
13201313
'username' => $this->user->getUsername(),
13211314
]);
1315+
$encoded = json_encode($params);
13221316

1323-
$strParams = serialize($params);
1324-
$b64Encoded = base64_encode($strParams);
1325-
1326-
return str_replace(['+', '/', '='], ['-', '_', '.'], $b64Encoded);
1317+
return $encoded;
13271318
}
13281319
}

main/webservices/api/v2.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
if ($hash) {
88
$hashParams = Rest::decodeParams($hash);
9-
10-
foreach ($hashParams as $key => $value) {
11-
$_REQUEST[$key] = $value;
9+
if (!empty($hashParams)) {
10+
foreach ($hashParams as $key => $value) {
11+
$_REQUEST[$key] = Security::remove_XSS($value);
12+
}
1213
}
1314
}
1415

0 commit comments

Comments
 (0)