elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.4k stars 1.19k forks source link

V3 Login throws Exception when Username or Password is null #4598

Closed polferov closed 11 months ago

polferov commented 1 year ago

Issue and how to reproduce

  1. create instance of Elsa Server and Elsa Studio (I am using Blazor Server)
  2. go to login
  3. leave username and/or password empty
  4. press login
  5. be sad because Exception

What is happening behind the scenes?

Elsa Studio calls the Elsa server's Login Endpoint.

The Endpoint receives a (Login)Request containg username and password. There is no validation being executed to check the values for null.

The endpoint starts out by calling .Trim() on the input values. This results in a NullReferenceException and a StatusCode 500.

    public override async Task<LoginResponse> ExecuteAsync(Request request, CancellationToken cancellationToken)
    {
        var user = await _userCredentialsValidator.ValidateAsync(request.Username.Trim(), request.Password.Trim(), cancellationToken);
        ...

Solution(?)

The Endpoint is built using FastEndpoints. While I am personally not familiar with this framework, I assume that adding a validator should not be too hard.

Additionally, input validation should also be implemented on the client side, providing feedback directly in the ui.

Proceeding-Proposal

As I am a backend engineer, I will take a look on the server side.

Also, as a backend engineer, my UIs may often be functional, though usually not very pretty. Hence, I would appreciate if someone with more UI skills than me, could help out with this :)


Note

I am using following versions:

      <PackageReference Include="Elsa" Version="3.0.0-preview.727" />
      <PackageReference Include="Elsa.Identity" Version="3.0.0-preview.727" />
      <PackageReference Include="Elsa.Workflows.Api" Version="3.0.0-preview.727" />

and

      <PackageReference Include="Elsa.Studio" Version="3.0.0-preview.94" />
      <PackageReference Include="Elsa.Studio.Core.BlazorServer" Version="3.0.0-preview.94" />
      <PackageReference Include="Elsa.Studio.Login.BlazorServer" Version="3.0.0-preview.94" />
sfmskywalker commented 11 months ago

Closing this, since a PR has been merged for this issue. Thanks again @polferov for your contributions!