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:
Erik Tate
2026-06-11 19:06:48 +00:00
committed by GitHub
co-authored by alhudz
parent 708dbb1bd9
commit b94988ebac
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -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")
}
+23
View File
@@ -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)
}