mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-19 01:58:44 +08:00
reject path separators in scp received file names (#67604)
Signed-off-by: Erik Tate <erik.tate@goteleport.com> Co-authored-by: alhudz <al.hudz.k@gmail.com>
This commit is contained in:
@@ -648,7 +648,8 @@ func parseNewFile(line string) (*newFileCmd, error) {
|
||||
// * https://sintonen.fi/advisories/scp-client-multiple-vulnerabilities.txt
|
||||
// * https://github.com/openssh/openssh-portable/commit/6010c03
|
||||
c.Name = parts[2]
|
||||
if len(c.Name) == 0 || strings.HasPrefix(c.Name, string(filepath.Separator)) || c.Name == "." || c.Name == ".." {
|
||||
if len(c.Name) == 0 || c.Name == "." || c.Name == ".." ||
|
||||
strings.ContainsRune(c.Name, '/') || strings.ContainsRune(c.Name, '\\') {
|
||||
return nil, trace.BadParameter("invalid name")
|
||||
}
|
||||
|
||||
|
||||
@@ -852,3 +852,26 @@ var testNow = time.Date(1984, time.April, 4, 0, 0, 0, 0, time.UTC)
|
||||
func args(params ...string) []string {
|
||||
return params
|
||||
}
|
||||
|
||||
func TestParseNewFileRejectsPathComponents(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
rejected := []string{
|
||||
"",
|
||||
".",
|
||||
"..",
|
||||
"/etc/passwd",
|
||||
"../../../tmp/evil",
|
||||
"sub/../../etc/passwd",
|
||||
"sub/evil",
|
||||
`sub\evil`,
|
||||
}
|
||||
for _, name := range rejected {
|
||||
_, err := parseNewFile("0644 10 " + name)
|
||||
require.Error(t, err, "name %q must be rejected", name)
|
||||
}
|
||||
|
||||
c, err := parseNewFile("0644 10 file.txt")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "file.txt", c.Name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user