Skip to content

Commit 99cd922

Browse files
committed
Doublehash the token to prevent timing attacks
1 parent c88cf5c commit 99cd922

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

core/lostpassword/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// Someone lost their password:
1414
if (isset($_POST['user'])) {
1515
if (OC_User::userExists($_POST['user'])) {
16-
$token = hash("sha256", $_POST['user'].OC_Util::generate_random_bytes(10));
17-
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token);
16+
$token = hash("sha256", OC_Util::generate_random_bytes(30).OC_Config::getValue('passwordsalt', ''));
17+
OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', hash("sha256", $token)); // Hash the token again to prevent timing attacks
1818
$email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', '');
1919
if (!empty($email)) {
2020
$link = OC_Helper::linkToAbsolute('core/lostpassword', 'resetpassword.php', array('user' => $_POST['user'], 'token' => $token));

core/lostpassword/resetpassword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require_once '../../lib/base.php';
1111

1212
// Someone wants to reset their password:
13-
if(isset($_GET['token']) && isset($_GET['user']) && OC_Preferences::getValue($_GET['user'], 'owncloud', 'lostpassword') === $_GET['token']) {
13+
if(isset($_GET['token']) && isset($_GET['user']) && OC_Preferences::getValue($_GET['user'], 'owncloud', 'lostpassword') === hash("sha256", $_GET['token'])) {
1414
if (isset($_POST['password'])) {
1515
if (OC_User::setPassword($_GET['user'], $_POST['password'])) {
1616
OC_Preferences::deleteKey($_GET['user'], 'owncloud', 'lostpassword');

0 commit comments

Comments
 (0)