Skip to content

Commit b674b7e

Browse files
committed
fix: potential panel login user-enumeration timing oracle;
1 parent 987eb55 commit b674b7e

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

internal/auth/auth.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ var (
3939
ErrForbidden = errors.New("forbidden")
4040
)
4141

42+
// loginDummyHash is compared against when a panel username is unknown, so
43+
// unknown-user and known-user-wrong-password logins take the same time
44+
var loginDummyHash, _ = bcrypt.GenerateFromPassword([]byte("podnest-login-timing-equalizer"), bcrypt.DefaultCost)
45+
4246
// LoginResult is returned by Login to indicate the outcome of a login attempt.
4347
type LoginResult struct {
4448
SessionID string
@@ -85,6 +89,9 @@ func Login(database *sql.DB, uname, password string) (*LoginResult, error) {
8589

8690
// If user is nil, it means the username does not exist
8791
if user == nil {
92+
// Compare against the dummy hash so the response time matches a real-user wrong password
93+
h := sha256.Sum256([]byte(password))
94+
_ = bcrypt.CompareHashAndPassword(loginDummyHash, []byte(fmt.Sprintf("%x", h)))
8895
logger.Error("failed to retrieve user: %v", ErrInvalidCredentials)
8996
return nil, ErrInvalidCredentials
9097
}

0 commit comments

Comments
 (0)