drakkan / sftpgo

Full-featured and highly configurable SFTP, HTTP/S, FTP/S and WebDAV server - S3, Google Cloud Storage, Azure Blob
https://sftpgo.com
GNU Affero General Public License v3.0
9.52k stars 739 forks source link

Improve end-user message when a technical error occurs in a external auth hook. #1749

Open Mathieu-COSYNS opened 2 months ago

Mathieu-COSYNS commented 2 months ago

Is your feature request related to a problem? Please describe.

When the external auth hook doesn't work properly (eg. hook is an http link to a server not working, hook return an invalid json user configuration, ...) the error message in the ui say "Invalid credentials, please retry" which is misleading for the users. They credentials may be valid but for some reason the hook fail. Thinking that their credentials are invalid they will retry, retry and retry again until they gave up or go insane.

image

Describe the solution you'd like

Show a message like a 500 error message instead of invalid credentials error message.

For example in this piece of web client code : https://github.com/drakkan/sftpgo/blob/3b5fba2eec04417319bbb4f4f2b93e1f4af2804b/internal/httpd/server.go#L267-L274 When dataprovider.CheckUserAndPass(...) return an error different than dataprovider.ErrInvalidCredentials instead of creating a new error with util.I18nErrorInvalidCredentials create a new error with util.I18nError500Message.

The example above only showcase a solution for the web client but this should also be considered for the web admin, and other protocols.

Describe alternatives you've considered

I have submitted the issue as a feature request because it doesn't break anything but it might as well be a bug.

What are you using SFTPGo for?

Private user, home usecase (home backup/VPS)

Additional context

Step to reproduce:

  1. Run docker run --rm -p 8080:8080 -e SFTPGO_DATA_PROVIDER__EXTERNAL_AUTH_HOOK=http://localhost -d "drakkan/sftpgo" without having anything running on http://localhost.
  2. After setting up the first admin account go directly to the webclient and try to login with any credentials. You will receive the message "Invalid credentials, please retry" but you also will see in the logs an entry with the message: error getting external auth hook HTTP response: Post \"http://localhost\": dial tcp [::1]:80: connect: connection refused witch is the real reason why you couldn't login and not the fact that you credentials where invalid.