Skip to content

Use constant-time comparison for passwords#31

Open
Lumberj3ck wants to merge 1 commit into
will-moss:masterfrom
Lumberj3ck:fix/auth-timing-attack
Open

Use constant-time comparison for passwords#31
Lumberj3ck wants to merge 1 commit into
will-moss:masterfrom
Lumberj3ck:fix/auth-timing-attack

Conversation

@Lumberj3ck

Copy link
Copy Markdown
Contributor

Description

This pull request addresses a vulnerability in the authentication process where password and hash comparisons might be vulnerable to timing attacks. The standard == operator was replaced with subtle.ConstantTimeCompare to ensure a constant-time comparison of secrets.

The Vulnerability

When comparing password123 with pxssword123, the comparison would stop at the second character. When comparing with password124, it would stop at the last character.

An attacker could exploit this behavior by sending slightly different passwords and measuring the server's response time. A longer response time implies that more characters in the supplied password are correct. By iteratively guessing one character at a time, an attacker could potentially reconstruct the entire password without ever knowing it beforehand.

Changes

This PR replaces comparisons with crypto/subtle.ConstantTimeCompare. This function always compares the full length of both byte slices, taking the same amount of time regardless of how many characters are correct.

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