Skip to content

Commit 7ea7c6b

Browse files
author
David Poll
committed
Merge pull request facebookarchive#64 from h0ke/master
Fix Remote Timing Attack vulnerability
2 parents 41e6c4f + 2e8d65a commit 7ea7c6b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/base_facebook.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,12 +1025,23 @@ protected function parseSignedRequest($signed_request) {
10251025
// check sig
10261026
$expected_sig = hash_hmac('sha256', $payload,
10271027
$this->getAppSecret(), $raw = true);
1028-
if ($sig !== $expected_sig) {
1028+
1029+
if (strlen($expected_sig) !== strlen($sig)) {
10291030
self::errorLog('Bad Signed JSON signature!');
10301031
return null;
10311032
}
10321033

1033-
return $data;
1034+
$result = 0;
1035+
for ($i = 0; $i < strlen($expected_sig); $i++) {
1036+
$result |= ord($expected_sig[$i]) ^ ord($sig[$i]);
1037+
}
1038+
1039+
if ($result == 0) {
1040+
return $data;
1041+
} else {
1042+
self::errorLog('Bad Signed JSON signature!');
1043+
return null;
1044+
}
10341045
}
10351046

10361047
/**

0 commit comments

Comments
 (0)