Skip to content

Commit

Permalink
bugfix: SimpleSAML\Utils\Crypto returns true for different strings us…
Browse files Browse the repository at this point in the history
…ing PHP < 5.6.

The reason was the lack of conversion to integer for each character of the strings before applying the XOR operator to them. The operator returns always an empty string when applied to two characters, and applying a binary-wise OR between 0 and an empty string, yields 0. Therefore, $diff is always 0, and the function returns true for every two strings with same length, regardless of their contents.
  • Loading branch information
jaimeperez committed May 5, 2017
1 parent f931e2e commit 4bc6296
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/SimpleSAML/Utils/Crypto.php
Expand Up @@ -404,8 +404,8 @@ public static function secureCompare($known, $user)
return false; // length differs
}
$diff = 0;
for ($i = 0; $i < $len; ++$i) {
$diff |= $known[$i] ^ $user[$i];
for ($i = 0; $i < $len; $i++) {
$diff |= ord($known[$i]) ^ ord($user[$i]);
}
// if all the bytes in $a and $b are identical, $diff should be equal to 0
return $diff === 0;
Expand Down

0 comments on commit 4bc6296

Please sign in to comment.