Skip to content

fix: remove panic() and relay password hashing errors to UI - #1014

Open
eternal-flame-AD wants to merge 1 commit into
masterfrom
bcrypt-errors
Open

fix: remove panic() and relay password hashing errors to UI#1014
eternal-flame-AD wants to merge 1 commit into
masterfrom
bcrypt-errors

Conversation

@eternal-flame-AD

Copy link
Copy Markdown
Member

Fixes #1013

@eternal-flame-AD
eternal-flame-AD requested a review from a team as a code owner July 27, 2026 11:56
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.69231% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.33%. Comparing base (d543a8a) to head (38eccee).

Files with missing lines Patch % Lines
api/user.go 40.00% 6 Missing and 3 partials ⚠️
database/database.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1014      +/-   ##
==========================================
- Coverage   74.53%   74.33%   -0.20%     
==========================================
  Files          66       66              
  Lines        3483     3499      +16     
==========================================
+ Hits         2596     2601       +5     
- Misses        688      695       +7     
- Partials      199      203       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread api/session_test.go
@@ -39,9 +39,14 @@ func (s *SessionSuite) BeforeTest(suiteName, testName string) {
s.notified = false
s.a = &SessionAPI{DB: s.db, NotifyDeleted: s.notify}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you thought about adding validation to the model, and letting the password handling as is? E.g.

	Pass string `json:"pass,omitempty" form:"pass" query:"pass" binding:"required,max=72"`

This likely makes the error message more explicit. I'm okay with the current solution, but this may be a better solution.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have to hardcode this number. I can see in the future users might request we migrate to other password hashes so I didn't go that route.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but the error message will be better, currently it's a 500 internal server error for something that the user provided an invalid value for. How about we do both? Your change and the extra validation?

Comment thread api/session_test.go Outdated
Comment thread auth/password/password.go
if err != nil {
panic(err)
if err != nil && err != bcrypt.ErrPasswordTooLong {
err = ErrUnexpectedError

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we mask the error here, we don't get the initial error anywhere, meaning if a user misconfigures the passstrength, it will always return unexpected error without any log about the actual error. I think we can pass the full error without masking into the 500 internal server error, and with the extra validation the length check is done before and results in a 400.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Can't create a new user, got a 500 error

2 participants