Skip to content
Snippets Groups Projects
Commit ca79bd5c authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #1727 from greezybacon/issue/login-dos


login: Require CSRF token to login

Reviewed-By: default avatarPeter Rotich <peter@osticket.com>
parents ca970b2a 504831fe
No related branches found
No related tags found
No related merge requests found
......@@ -53,12 +53,15 @@ Class CSRF {
return $this->name;
}
function getToken() {
function rotate() {
$this->csrf['token'] = sha1(session_id().Crypto::random(16).SECRET_SALT);
$this->csrf['time'] = time();
}
if(!$this->csrf['token'] || $this->isExpired()) {
function getToken() {
$this->csrf['token'] = sha1(session_id().Crypto::random(16).SECRET_SALT);
$this->csrf['time'] = time();
if (!$this->csrf['token'] || $this->isExpired()) {
$this->rotate();
} else {
//Reset the timer
$this->csrf['time'] = time();
......
......@@ -31,6 +31,20 @@ else
$inc = 'login.inc.php';
$suggest_pwreset = false;
// Check the CSRF token, and ensure that future requests will have to use a
// different CSRF token. This will help ward off both parallel and serial
// brute force attacks, because new tokens will have to be requested for
// each attempt.
if ($_POST) {
// Check CSRF token
if (!$ost->checkCSRFToken())
Http::response(400, __('Valid CSRF Token Required'));
// Rotate the CSRF token (original cannot be reused)
$ost->getCSRF()->rotate();
}
if ($_POST && isset($_POST['luser'])) {
if (!$_POST['luser'])
$errors['err'] = __('Valid username or email address is required');
......
......@@ -31,6 +31,16 @@ $msg = $msg ?: ($content ? $content->getName() : __('Authentication Required'));
$dest=($dest && (!strstr($dest,'login.php') && !strstr($dest,'ajax.php')))?$dest:'index.php';
$show_reset = false;
if($_POST) {
// Check the CSRF token, and ensure that future requests will have to
// use a different CSRF token. This will help ward off both parallel and
// serial brute force attacks, because new tokens will have to be
// requested for each attempt.
if (!$ost->checkCSRFToken())
Http::response(400, __('Valid CSRF Token Required'));
// Rotate the CSRF token (original cannot be reused)
$ost->getCSRF()->rotate();
// Lookup support backends for this staff
$username = trim($_POST['userid']);
if ($user = StaffAuthenticationBackend::process($username,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment