Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insecure login-controller? #13

Open
dermarlo opened this issue Apr 16, 2023 · 0 comments
Open

Insecure login-controller? #13

dermarlo opened this issue Apr 16, 2023 · 0 comments

Comments

@dermarlo
Copy link

I think it would be better practice in login_controller.go to only issue a bearer token after explicitely checking that the user-provided password matches the hash after using bcrypt. In its current state the default is to provide a token if one specific error is not met.

if err != nil && err == bcrypt.ErrMismatchedHashAndPassword {

From what I understand the only case where this might be kind of exploited is, when the DB-stored passwords are not bcrypt hashes, which results in:
var ErrHashTooShort = "crypto/bcrypt: hashedSecret too short to be a bcrypted password"

I had that case because I had unencrypted test-data in my database.

Eventhough the attack surface might be limited here I would suggest to modify the code to teach and encourage safe best-practices.

How to validate:

  • Register a new user
  • change the bcrypt hash in the database to "test"
  • Login with any password will issue a token from now on
  • ...
  • Profit :-)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant