Skip to content

Commit 4a6466c

Browse files
committed
Remove environment variable parsing from SSH server
This removes the environment variable parsing code from the SSH server, which never worked in the first place. Since environment variable passing doesn't appear to be necessary for the built-in SSH server to work properly, it's removed to reduce attack surface rather than fixing it. The current code processes (untrusted) input in a buggy manner and passes it to a process invocation which doesn't actually do anything. I don't *think* this is an exploitable vulnerability but I haven't looked at it in detail, and it wouldn't really surprise me if it was. Closes #1935, an alternative proposal which which partially fixes the environment variable handling but ultimately still leaves it broken. Signed-off-by: Hugo Landau <[email protected]>
1 parent 85414d8 commit 4a6466c

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

modules/ssh/ssh.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2014 The Gogs Authors. All rights reserved.
2+
// Copyright 2018 The Gitea Authors. All rights reserved.
23
// Use of this source code is governed by a MIT-style
34
// license that can be found in the LICENSE file.
45

@@ -47,18 +48,6 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) {
4748
for req := range in {
4849
payload := cleanCommand(string(req.Payload))
4950
switch req.Type {
50-
case "env":
51-
args := strings.Split(strings.Replace(payload, "\x00", "", -1), "\v")
52-
if len(args) != 2 {
53-
log.Warn("SSH: Invalid env arguments: '%#v'", args)
54-
continue
55-
}
56-
args[0] = strings.TrimLeft(args[0], "\x04")
57-
_, _, err := com.ExecCmdBytes("env", args[0]+"="+args[1])
58-
if err != nil {
59-
log.Error(3, "env: %v", err)
60-
return
61-
}
6251
case "exec":
6352
cmdName := strings.TrimLeft(payload, "'()")
6453
log.Trace("SSH: Payload: %v", cmdName)

0 commit comments

Comments
 (0)