#315: set a 10 sec deadline for clients to complete the handshake

This commit is contained in:
Akshay Shekher 2020-01-04 14:22:10 -08:00
parent 0a122be81e
commit de89c87946

View File

@ -2,6 +2,7 @@ package sshd
import ( import (
"net" "net"
"time"
"github.com/shazow/rateio" "github.com/shazow/rateio"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
@ -32,12 +33,18 @@ func (l *SSHListener) handleConn(conn net.Conn) (*Terminal, error) {
conn = ReadLimitConn(conn, l.RateLimit()) conn = ReadLimitConn(conn, l.RateLimit())
} }
// Handshake shouldn't take more than 10 seconds
conn.SetReadDeadline(time.Now().Add(10 * time.Second))
// Upgrade TCP connection to SSH connection // Upgrade TCP connection to SSH connection
sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config) sshConn, channels, requests, err := ssh.NewServerConn(conn, l.config)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// clear the deadline
conn.SetDeadline(time.Time{})
// FIXME: Disconnect if too many faulty requests? (Avoid DoS.) // FIXME: Disconnect if too many faulty requests? (Avoid DoS.)
go ssh.DiscardRequests(requests) go ssh.DiscardRequests(requests)
return NewSession(sshConn, channels) return NewSession(sshConn, channels)