Skip to content

Commit

Permalink
Security fix #2532
Browse files Browse the repository at this point in the history
- Use json_decode/json_encode instead base64
- Add Security::remove_XSSS
  • Loading branch information
jmontoyaa committed May 29, 2018
1 parent 9076126 commit 0de8470
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
17 changes: 4 additions & 13 deletions main/inc/lib/webservices/Rest.php
Expand Up @@ -823,16 +823,9 @@ public function getCourseLearnPaths()
*/
public static function decodeParams($encoded)
{
$decoded = str_replace(['-', '_', '.'], ['+', '/', '='], $encoded);
$mod4 = strlen($decoded) % 4;
$decoded = json_decode($encoded);

if ($mod4) {
$decoded .= substr('====', $mod4);
}

$b64Decoded = base64_decode($decoded);

return unserialize($b64Decoded);
return $decoded;
}

/**
Expand Down Expand Up @@ -1319,10 +1312,8 @@ private function encodeParams(array $additionalParams = [])
'api_key' => $this->apiKey,
'username' => $this->user->getUsername(),
]);
$encoded = json_encode($params);

$strParams = serialize($params);
$b64Encoded = base64_encode($strParams);

return str_replace(['+', '/', '='], ['-', '_', '.'], $b64Encoded);
return $encoded;
}
}
7 changes: 4 additions & 3 deletions main/webservices/api/v2.php
Expand Up @@ -6,9 +6,10 @@

if ($hash) {
$hashParams = Rest::decodeParams($hash);

foreach ($hashParams as $key => $value) {
$_REQUEST[$key] = $value;
if (!empty($hashParams)) {
foreach ($hashParams as $key => $value) {
$_REQUEST[$key] = Security::remove_XSS($value);
}
}
}

Expand Down

2 comments on commit 0de8470

@ywarnier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should go with a note in changelog.html (at the end, WS section) for 1.11.8 about changing web services (just in case someone would be using these REST services with the previous syntax)

@jmontoyaa
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm waiting confirmation that this fixes the error.

Please sign in to comment.