Skip to content

Commit d1bb7a9

Browse files
fix: address feedback on PR
1 parent f028da9 commit d1bb7a9

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/Core/Utilities/EnumerationProtectionHelpers.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ namespace Bit.Core.Utilities;
55
public static class EnumerationProtectionHelpers
66
{
77
/// <summary>
8-
/// Use this method to get a consistent int result based on the salt that is in the range.
9-
/// The same salt will always return the same index result based on range input.
8+
/// Use this method to get a consistent int result based on the inputString that is in the range.
9+
/// The same inputString will always return the same index result based on range input.
1010
/// </summary>
1111
/// <param name="hmacKey">Key used to derive the HMAC hash. Use a different key for each usage for optimal security</param>
12-
/// <param name="salt">The string to derive an index result</param>
12+
/// <param name="inputString">The string to derive an index result</param>
1313
/// <param name="range">The range of possible index values</param>
14-
/// <returns>An int between 0 and range</returns>
15-
public static int GetIndexForSaltHash(byte[] hmacKey, string salt, int range)
14+
/// <returns>An int between 0 and range - 1</returns>
15+
public static int GetIndexForSaltHash(byte[] hmacKey, string inputString, int range)
1616
{
1717
if (hmacKey == null || range <= 0 || hmacKey.Length == 0)
1818
{
@@ -21,7 +21,7 @@ public static int GetIndexForSaltHash(byte[] hmacKey, string salt, int range)
2121
else
2222
{
2323
// Compute the HMAC hash of the salt
24-
var hmacMessage = Encoding.UTF8.GetBytes(salt.Trim().ToLowerInvariant());
24+
var hmacMessage = Encoding.UTF8.GetBytes(inputString.Trim().ToLowerInvariant());
2525
using var hmac = new System.Security.Cryptography.HMACSHA256(hmacKey);
2626
var hmacHash = hmac.ComputeHash(hmacMessage);
2727
// Convert the hash to a number

src/Identity/IdentityServer/RequestValidators/SendAccess/SendAccessConstants.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@ public static class TokenRequest
3737
public static class GrantValidatorResults
3838
{
3939
/// <summary>
40-
/// The sendId is valid and the request is well formed. Not returned in any response.
40+
/// The <see cref="TokenRequest.SendId"/> in the request is a valid GUID and the request is well formed. Not returned in any response.
4141
/// </summary>
42-
public const string ValidGuid = "valid_send_guid";
42+
public const string ValidSendGuid = "valid_send_guid";
4343
/// <summary>
44-
/// The sendId is missing from the request.
44+
/// The <see cref="TokenRequest.SendId"/> is missing from the request.
4545
/// </summary>
4646
public const string SendIdRequired = "send_id_required";
4747
/// <summary>
48-
/// The sendId is invalid, does not match a known send.
48+
/// The <see cref="TokenRequest.SendId"/> is invalid, does not match a known send.
4949
/// </summary>
5050
public const string InvalidSendId = "send_id_invalid";
5151
}
5252

5353
public static class PasswordValidatorResults
5454
{
5555
/// <summary>
56-
/// The passwordHashB64 does not match the send's password hash.
56+
/// The <see cref="TokenRequest.ClientB64HashedPassword"/> does not match the send's password hash.
5757
/// </summary>
5858
public const string RequestPasswordDoesNotMatch = "password_hash_b64_invalid";
5959
/// <summary>
60-
/// The passwordHashB64 is missing from the request.
60+
/// The <see cref="TokenRequest.ClientB64HashedPassword"/> is missing from the request.
6161
/// </summary>
6262
public const string RequestPasswordIsRequired = "password_hash_b64_required";
6363
}

src/Identity/IdentityServer/RequestValidators/SendAccess/SendNeverAuthenticateRequestValidator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
namespace Bit.Identity.IdentityServer.RequestValidators.SendAccess;
99

10+
/// <summary>
11+
/// This class is used to protect our system from enumeration attacks. This Validator will always return an error result.
12+
/// We hash the SendId Guid passed into the request to select the an error from the list of possible errors. This ensures
13+
/// that the same error is always returned for the same SendId.
14+
/// </summary>
15+
/// <param name="globalSettings">We need access to a hash key to generate the error index.</param>
1016
public class SendNeverAuthenticateRequestValidator(GlobalSettings globalSettings) : ISendAuthenticationMethodValidator<NeverAuthenticate>
1117
{
1218
private readonly string[] _errorOptions =

0 commit comments

Comments
 (0)