-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
It turns out that some users do provide unclean paths like "foo/bar/" and as a result the new behaviour in commit bc750ad ("join: return an error if root is unclean path") was far too aggressive and lead to regressions. The more gentle solution is to only error out if the path contains a ".." component (which is the only component type we are really worried about here because it's the only one that can turn a safe root-joined-path into an unsafe one due to how symlinks are resolved on Linux). Fixes: bc750ad ("join: return an error if root is unclean path") Signed-off-by: Aleksa Sarai <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (C) 2017-2025 SUSE LLC. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package securejoin | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Windows has very specific behaviour relating to volumes, and we can only | ||
// test it on Windows machines because filepath.* behaviour depends on GOOS. | ||
func TestHasDotDot_WindowsVolumes(t *testing.T) { | ||
for _, test := range []struct { | ||
testName, path string | ||
expected bool | ||
}{ | ||
{"plain-dotdot", `C:..`, true}, // apparently legal | ||
{"relative-dotdot", `C:..\foo\bar`, true}, // apparently legal | ||
{"trailing-dotdot", `D:\foo\bar\..`, true}, | ||
{"leading-dotdot", `F:\..\foo\bar`, true}, | ||
{"middle-dotdot", `F:\foo\..\bar`, true}, | ||
{"drive-like-path", `\foo\C:..\bar`, false}, // C:.. is a filename here | ||
{"unc-dotdot", `\\gondor\share\call\for\aid\..\help`, true}, | ||
{"dos-dotpath-relative-dotdot", `\\.\C:..\foo\bar`, true}, | ||
{"dos-dotpath-dotdot", `\\.\C:\foo\..\bar`, true}, | ||
{"dos-questionpath-relative-dotdot", `\\?\C:..\foo\bar`, true}, // apparently legal | ||
{"dos-questionpath-dotdot", `\\?\C:\foo\..\bar`, true}, // apparently legal | ||
} { | ||
test := test // copy iterator | ||
t.Run(test.testName, func(t *testing.T) { | ||
got := hasDotDot(test.path) | ||
assert.Equalf(t, test.expected, got, "unexpected result for hasDotDot(`%s`) (VolumePath: %q)", test.path, filepath.VolumePath(test.path)) | ||
Check failure on line 36 in join_windows_test.go
|
||
}) | ||
} | ||
} |