Skip to content

Commit

Permalink
Merge branch 'security/5.0.2-releng' into 5.0.2-releng
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Sep 14, 2021
2 parents 92ff0e3 + 15707a3 commit 2427aee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions lib/RT/Interface/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -842,10 +842,18 @@ sub AttemptPasswordAuthentication {
my $user_obj = RT::CurrentUser->new();
$user_obj->Load( $ARGS->{user} );

# Load the RT system user as well to avoid timing side channel
my $system_user = RT::CurrentUser->new();
$system_user->Load(1); # User with ID 1 should always exist!

my $m = $HTML::Mason::Commands::m;

my $remote_addr = RequestENV('REMOTE_ADDR');
unless ( $user_obj->id && $user_obj->IsPassword( $ARGS->{pass} ) ) {
if (!$user_obj->id) {
# Avoid timing side channel... always run IsPassword
$system_user->IsPassword( $ARGS->{pass} );
}
$RT::Logger->error("FAILED LOGIN for @{[$ARGS->{user}]} from $remote_addr");
$m->callback( %$ARGS, CallbackName => 'FailedLogin', CallbackPage => '/autohandler' );
return (0, HTML::Mason::Commands::loc('Your username or password is incorrect'));
Expand Down
9 changes: 9 additions & 0 deletions lib/RT/REST2/Middleware/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,19 @@ sub login_from_basicauth {
my($user, $pass) = split /:/, (MIME::Base64::decode($1) || ":"), 2;
my $cu = RT::CurrentUser->new;
$cu->Load($user);

# Load the RT system user as well to avoid timing side channel
my $system_user = RT::CurrentUser->new();
$system_user->Load(1); # User with ID 1 should always exist!

if ($cu->id and $cu->IsPassword($pass)) {
return $cu;
}
else {
if (!$cu->id) {
# Avoid timing side channel... always run IsPassword
$system_user->IsPassword($pass);
}
RT->Logger->info("Failed login for $user");
return;
}
Expand Down
9 changes: 6 additions & 3 deletions lib/RT/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1237,15 +1237,18 @@ sub IsPassword {
}

if ( $self->PrincipalObj->Disabled ) {
# Run the bcrypt generator to avoid timing side-channel attacks
RT::Util::constant_time_eq($self->_GeneratePassword_bcrypt($value), '0' x 64);
$RT::Logger->info(
"Disabled user " . $self->Name . " tried to log in" );
return (undef);
}

unless ($self->HasPassword) {
return(undef);
}

# Run the bcrypt generator to avoid timing side-channel attacks
RT::Util::constant_time_eq($self->_GeneratePassword_bcrypt($value), '0' x 64);
return undef;
}
my $stored = $self->__Value('Password');
if ($stored =~ /^!/) {
# If it's a new-style (>= RT 4.0) password, it starts with a '!'
Expand Down

0 comments on commit 2427aee

Please sign in to comment.