Skip to content

security: use constant-time comparison for password hash check - #104

Open
tas50 wants to merge 1 commit into
ctdk:masterfrom
tas50:fix/constant-time-passwd
Open

security: use constant-time comparison for password hash check#104
tas50 wants to merge 1 commit into
ctdk:masterfrom
tas50:fix/constant-time-passwd

Conversation

@tas50

@tas50 tas50 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Issue

User.CheckPasswd compares the stored password hash against the freshly computed hash with !=:

if u.Passwd() != h {
    return util.Errorf("password did not match")
}

Go's string != short-circuits on the first differing byte, so comparison time leaks how many leading bytes matched. The /authenticate_user endpoint is unauthenticated and accepts an attacker-controlled name/password, making this a timing oracle on the hash comparison — exactly the path where a constant-time comparison is expected.

Fix

Compare with crypto/subtle.ConstantTimeCompare.

Verification

go build ./..., go vet ./user/, and go test ./user/ pass.

CheckPasswd compared the stored password hash against the computed hash
with the `!=` operator, which short-circuits on the first differing
byte. This endpoint (/authenticate_user) is unauthenticated and accepts
an attacker-supplied name/password, so the comparison is a timing
oracle. Use crypto/subtle.ConstantTimeCompare instead.

Signed-off-by: Tim Smith <tsmith84@proton.me>
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

Successfully merging this pull request may close these issues.

1 participant