Skip to content

Commit 94e4899

Browse files
committed
Update login to return 400 bad request instead of 404 not found for unknown login ID to prevent revealing existence
1 parent 4be0d2c commit 94e4899

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

application/account-management/Core/Features/Authentication/Commands/CompleteLogin.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public async Task<Result> Handle(CompleteLoginCommand command, CancellationToken
3434
{
3535
var login = await loginRepository.GetByIdAsync(command.Id, cancellationToken);
3636

37-
if (login is null) return Result.NotFound($"Login with id '{command.Id}' not found.");
37+
if (login is null)
38+
{
39+
// For security, avoid confirming the existence of login IDs
40+
return Result.BadRequest("The code is wrong or no longer valid.");
41+
}
3842

3943
if (login.Completed)
4044
{

application/account-management/Tests/Authentication/CompleteLoginTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public async Task CompleteLogin_WhenValid_ShouldCompleteLoginAndCreateTokens()
4747
}
4848

4949
[Fact]
50-
public async Task CompleteLogin_WhenLoginNotFound_ShouldReturnNotFound()
50+
public async Task CompleteLogin_WhenLoginNotFound_ShouldReturnBadRequest()
5151
{
5252
// Arrange
5353
var invalidLoginId = LoginId.NewId();
@@ -57,8 +57,7 @@ public async Task CompleteLogin_WhenLoginNotFound_ShouldReturnNotFound()
5757
var response = await AnonymousHttpClient.PostAsJsonAsync($"/api/account-management/authentication/login/{invalidLoginId}/complete", command);
5858

5959
// Assert
60-
var expectedDetail = $"Login with id '{invalidLoginId}' not found.";
61-
await response.ShouldHaveErrorStatusCode(HttpStatusCode.NotFound, expectedDetail);
60+
await response.ShouldHaveErrorStatusCode(HttpStatusCode.BadRequest, "The code is wrong or no longer valid.");
6261

6362
TelemetryEventsCollectorSpy.AreAllEventsDispatched.Should().BeFalse();
6463
TelemetryEventsCollectorSpy.CollectedEvents.Should().BeEmpty();

0 commit comments

Comments
 (0)