Skip to content

Commit f02f324

Browse files
committed
fix: 解决终端连接注入漏洞问题
1 parent 57916ed commit f02f324

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

backend/app/api/v1/terminal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ func (b *BaseApi) ContainerWsSsh(c *gin.Context) {
163163
}
164164
defer wsConn.Close()
165165

166-
cmds := fmt.Sprintf("docker exec %s %s", containerID, command)
166+
cmds := []string{"exec", containerID, command}
167167
if len(user) != 0 {
168-
cmds = fmt.Sprintf("docker exec -u %s %s %s", user, containerID, command)
168+
cmds = []string{"exec", "-u", user, containerID, command}
169169
}
170-
stdout, err := cmd.Exec(cmds)
170+
stdout, err := cmd.ExecWithCheck("docker", cmds...)
171171
if wshandleError(wsConn, errors.WithMessage(err, stdout)) {
172172
return
173173
}

backend/utils/terminal/local_cmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"unsafe"
99

1010
"github.com/1Panel-dev/1Panel/backend/global"
11+
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
1112
"github.com/creack/pty"
1213
"github.com/pkg/errors"
1314
)
@@ -26,6 +27,9 @@ type LocalCommand struct {
2627
}
2728

2829
func NewCommand(commands string) (*LocalCommand, error) {
30+
if cmd.CheckIllegal(commands) {
31+
return nil, errors.New("There are invalid characters in the command you're executing.")
32+
}
2933
cmd := exec.Command("sh", "-c", commands)
3034

3135
pty, err := pty.Start(cmd)

0 commit comments

Comments
 (0)