mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 21:48:12 -05:00
CSA-29: Time safe comparison for access code (#2431)
* time safe comparison for access code * remove whitespace
This commit is contained in:
parent
d8834793b5
commit
41ee3d4c69
@ -6,6 +6,7 @@ using Bit.Core.Exceptions;
|
|||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Settings;
|
using Bit.Core.Settings;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ public class AuthRequestsController : Controller
|
|||||||
public async Task<AuthRequestResponseModel> GetResponse(string id, [FromQuery] string code)
|
public async Task<AuthRequestResponseModel> GetResponse(string id, [FromQuery] string code)
|
||||||
{
|
{
|
||||||
var authRequest = await _authRequestRepository.GetByIdAsync(new Guid(id));
|
var authRequest = await _authRequestRepository.GetByIdAsync(new Guid(id));
|
||||||
if (authRequest == null || code != authRequest.AccessCode || authRequest.GetExpirationDate() < DateTime.UtcNow)
|
if (authRequest == null || !CoreHelpers.FixedTimeEquals(authRequest.AccessCode, code) || authRequest.GetExpirationDate() < DateTime.UtcNow)
|
||||||
{
|
{
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Bit.Core.LoginFeatures.PasswordlessLogin.Interfaces;
|
using Bit.Core.LoginFeatures.PasswordlessLogin.Interfaces;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Core.LoginFeatures.PasswordlessLogin;
|
namespace Bit.Core.LoginFeatures.PasswordlessLogin;
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ public class VerifyAuthRequestCommand : IVerifyAuthRequestCommand
|
|||||||
public async Task<bool> VerifyAuthRequestAsync(Guid authRequestId, string accessCode)
|
public async Task<bool> VerifyAuthRequestAsync(Guid authRequestId, string accessCode)
|
||||||
{
|
{
|
||||||
var authRequest = await _authRequestRepository.GetByIdAsync(authRequestId);
|
var authRequest = await _authRequestRepository.GetByIdAsync(authRequestId);
|
||||||
if (authRequest == null || authRequest.AccessCode != accessCode)
|
if (authRequest == null || !CoreHelpers.FixedTimeEquals(authRequest.AccessCode, accessCode))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user