diff options
author | Frank Karlitschek <karlitschek@kde.org> | 2012-04-26 19:35:33 +0200 |
---|---|---|
committer | Frank Karlitschek <karlitschek@kde.org> | 2012-04-26 19:35:33 +0200 |
commit | 6bdefef31e87f6c1be2ed7693fd2f6d203e32462 (patch) | |
tree | 18a59be2634f10adfdeec8ff399b5f70ccd48616 /core | |
parent | 127796218314c6b1f19ba86f74caa913375aac8d (diff) | |
download | nextcloud-server-6bdefef31e87f6c1be2ed7693fd2f6d203e32462.tar.gz nextcloud-server-6bdefef31e87f6c1be2ed7693fd2f6d203e32462.zip |
csrf protection
Diffstat (limited to 'core')
-rw-r--r-- | core/lostpassword/index.php | 19 | ||||
-rw-r--r-- | core/lostpassword/templates/lostpassword.php | 1 |
2 files changed, 14 insertions, 6 deletions
diff --git a/core/lostpassword/index.php b/core/lostpassword/index.php index b6cdd601d66..2b87a1eb111 100644 --- a/core/lostpassword/index.php +++ b/core/lostpassword/index.php @@ -9,13 +9,14 @@ $RUNTIME_NOAPPS = TRUE; //no apps require_once('../../lib/base.php'); + // Someone lost their password: if (isset($_POST['user'])) { if (OC_User::userExists($_POST['user'])) { $token = sha1($_POST['user'].md5(uniqid(rand(), true))); OC_Preferences::setValue($_POST['user'], 'owncloud', 'lostpassword', $token); $email = OC_Preferences::getValue($_POST['user'], 'settings', 'email', ''); - if (!empty($email)) { + if (!empty($email) and isset($_POST['sectoken']) and isset($_SESSION['sectoken']) and ($_POST['sectoken']==$_SESSION['sectoken']) ) { $link = OC_Helper::linkToAbsolute('core/lostpassword', 'resetpassword.php').'?user='.$_POST['user'].'&token='.$token; $tmpl = new OC_Template('core/lostpassword', 'email'); $tmpl->assign('link', $link); @@ -23,14 +24,20 @@ if (isset($_POST['user'])) { $l = OC_L10N::get('core'); $from = 'lostpassword-noreply@' . $_SERVER['HTTP_HOST']; $r=mail($email, $l->t('Owncloud password reset'), $msg, 'From:' . $from); -//if($r==false) echo('error'); else echo('works!!!!!!!'); - OC_MAIL::send($email,$_POST['user'],$l->t('Owncloud password reset'),$msg,$from,'ownCloud'); + OC_MAIL::send($email,$_POST['user'],$l->t('ownCloud password reset'),$msg,$from,'ownCloud'); + echo('sent'); } - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true)); + $sectoken=rand(1000000,9999999); + $_SESSION['sectoken']=$sectoken; + OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => true, 'sectoken' => $sectoken)); } else { - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => true, 'requested' => false)); + $sectoken=rand(1000000,9999999); + $_SESSION['sectoken']=$sectoken; + OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => true, 'requested' => false, 'sectoken' => $sectoken)); } } else { - OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => false)); + $sectoken=rand(1000000,9999999); + $_SESSION['sectoken']=$sectoken; + OC_Template::printGuestPage('core/lostpassword', 'lostpassword', array('error' => false, 'requested' => false, 'sectoken' => $sectoken)); } diff --git a/core/lostpassword/templates/lostpassword.php b/core/lostpassword/templates/lostpassword.php index 4b871963b80..754eabdad67 100644 --- a/core/lostpassword/templates/lostpassword.php +++ b/core/lostpassword/templates/lostpassword.php @@ -10,6 +10,7 @@ <p class="infield"> <label for="user" class="infield"><?php echo $l->t( 'Username' ); ?></label> <input type="text" name="user" id="user" value="" autocomplete="off" required autofocus /> + <input type="hidden" name="sectoken" id="sectoken" value="<?php echo($_['sectoken']); ?>" /> </p> <input type="submit" id="submit" value="<?php echo $l->t('Request reset'); ?>" /> <?php endif; ?> |