Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: socks5 usernames and passwords can BOTH be up to 255 bytes #343

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions transport/socks5/socks5.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,24 @@ func ClientHandshake(rw io.ReadWriter, addr Addr, command Command, user *User) (
return nil, errors.New("auth required")
}

authMsgLen := 1 + 1 + len(user.Username) + 1 + len(user.Password)
if authMsgLen > MaxAuthLen {
return nil, errors.New("auth message too long")
uLen := len(user.Username)
pLen := len(user.Password)

// Both ULEN and PLEN are limited to the range [1, 255].
if uLen == 0 || pLen == 0 {
return nil, errors.New("auth username/password empty")
} else if uLen > MaxAuthLen || pLen > MaxAuthLen {
return nil, errors.New("auth username/password too long")
}

authMsgLen := 1 + 1 + uLen + 1 + pLen

// password protocol version
authMsg := bytes.NewBuffer(make([]byte, 0, authMsgLen))
authMsg.WriteByte(0x01 /* VER */)
authMsg.WriteByte(byte(len(user.Username)) /* ULEN */)
authMsg.WriteByte(byte(uLen) /* ULEN */)
authMsg.WriteString(user.Username /* UNAME */)
authMsg.WriteByte(byte(len(user.Password)) /* PLEN */)
authMsg.WriteByte(byte(pLen) /* PLEN */)
authMsg.WriteString(user.Password /* PASSWD */)

if _, err := rw.Write(authMsg.Bytes()); err != nil {
Expand Down
Loading