mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
net/socks5: compare proxy auth credentials in constant time
The SOCKS5 server checked the client-supplied username and password against the configured credentials with plain string equality, which returns on the first differing byte. In tsnet the password is a random 128-bit value that gates every dial out through the node, and the listener is on 127.0.0.1, so a local process can time the auth reject to recover it a byte at a time with unlimited attempts and no lockout. The LocalAPI sharing the same loopback listener already compares its credential with subtle.ConstantTimeCompare; do the same here for both fields, evaluating both so the username result does not gate whether the password is examined. Updates #20998 Signed-off-by: basavaraj-sm05 <[email protected]>
This commit is contained in:
1 parent
1e69418c29
commit
60576f8bd1
1 file changed
+9
-1
@@ -15,6 +15,7 @@ package socks5
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -173,7 +174,14 @@ func (c *Conn) Run() error {
|
||||
}
|
||||
|
||||
user, pwd, err := parseClientAuth(c.clientConn)
|
||||
if err != nil || user != c.srv.Username || pwd != c.srv.Password {
|
||||
// Compare both credentials in constant time. The listener is reachable by
|
||||
// any local process, so a data-dependent comparison would let one recover
|
||||
// the username or password a byte at a time by timing the reject. Evaluate
|
||||
// both halves unconditionally so the username result doesn't gate whether
|
||||
// the password is examined.
|
||||
userMatch := subtle.ConstantTimeCompare([]byte(user), []byte(c.srv.Username))
|
||||
pwdMatch := subtle.ConstantTimeCompare([]byte(pwd), []byte(c.srv.Password))
|
||||
if err != nil || userMatch != 1 || pwdMatch != 1 {
|
||||
c.clientConn.Write([]byte{1, 1}) // auth error
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user