Skip to content

[H2] Basic auth uses timing-vulnerable plaintext comparison #273

Description

@pradeepto

Severity: High

Category

Authentication Failures (OWASP A07)

Files

internal/httpapi/middleware/basic_auth.go:39

Description

Password comparison uses == which short-circuits on the first mismatched byte. Leaks timing information about how many leading bytes match. No rate limiting makes this worse since an attacker can run many attempts quickly.

// line 39
if username == u.Username && password == u.Password {

Fix

import "crypto/subtle"

usernameMatch := subtle.ConstantTimeCompare([]byte(username), []byte(u.Username))
passwordMatch := subtle.ConstantTimeCompare([]byte(password), []byte(u.Password))
if usernameMatch == 1 && passwordMatch == 1 {
    authorized = true
    break
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsecurity-fix-requiredSecurity vulnerability requiring fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions