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

Prevent unknown ssh requests from terminating sessions #23874

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions lib/srv/forward/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,13 @@ func (s *Server) dispatch(ctx context.Context, ch ssh.Channel, req *ssh.Request,
case sshutils.PuTTYWinadjRequest:
return s.handlePuTTYWinadj(ch, req)
default:
return trace.BadParameter(
"%v doesn't support request type '%v'", s.Component(), req.Type)
s.log.Warnf("%v doesn't support request type '%v'", s.Component(), req.Type)
if req.WantReply {
if err := req.Reply(false, nil); err != nil {
s.log.Errorf("sending error reply on SSH channel: %v", err)
}
}
return nil
}
}

Expand Down
18 changes: 14 additions & 4 deletions lib/srv/regular/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,13 @@ func (s *Server) dispatch(ctx context.Context, ch ssh.Channel, req *ssh.Request,
s.Logger.Debugf("%v: deliberately ignoring request for '%v' channel", s.Component(), sshutils.PuTTYSimpleRequest)
return nil
default:
return trace.BadParameter(
"(%v) proxy doesn't support request type '%v'", s.Component(), req.Type)
s.Logger.Warnf("(%v) proxy doesn't support request type '%v'", s.Component(), req.Type)
if req.WantReply {
if err := req.Reply(false, nil); err != nil {
s.Logger.Errorf("sending error reply on SSH channel: %v", err)
}
}
return nil
}
}

Expand Down Expand Up @@ -1688,8 +1693,13 @@ func (s *Server) dispatch(ctx context.Context, ch ssh.Channel, req *ssh.Request,
case sshutils.PuTTYWinadjRequest:
return s.handlePuTTYWinadj(ch, req)
default:
return trace.BadParameter(
"%v doesn't support request type '%v'", s.Component(), req.Type)
s.Logger.Warnf("%v doesn't support request type '%v'", s.Component(), req.Type)
if req.WantReply {
if err := req.Reply(false, nil); err != nil {
s.Logger.Errorf("sending error reply on SSH channel: %v", err)
}
}
return nil
}
}

Expand Down
24 changes: 24 additions & 0 deletions lib/srv/regular/sshserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,30 @@ func TestEnvs(t *testing.T) {
}
}

// TestUnknownRequest validates that any unknown session
// requests do not terminate the session.
func TestUnknownRequest(t *testing.T) {
t.Parallel()
ctx := context.Background()

f := newFixtureWithoutDiskBasedLogging(t)

se, err := f.ssh.clt.NewSession(ctx)
require.NoError(t, err)
defer se.Close()

// send a random request that won't be handled
ok, err := se.SendRequest(ctx, uuid.NewString(), true, nil)
require.NoError(t, err)
require.False(t, ok)

// ensure the session is still active
require.NoError(t, se.Setenv(ctx, "HOME_TEST", "/test"))
output, err := se.Output(ctx, "env")
require.NoError(t, err)
require.Contains(t, string(output), "HOME_TEST=/test")
}

// TestNoAuth tries to log in with no auth methods and should be rejected
func TestNoAuth(t *testing.T) {
t.Parallel()
Expand Down