Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e01d00bc31 |
@@ -107,6 +107,7 @@ All `path` values must satisfy these invariants:
|
|||||||
- **Forward slashes**: use `/` as the path separator (never `\`)
|
- **Forward slashes**: use `/` as the path separator (never `\`)
|
||||||
- **Relative only**: no leading `/`
|
- **Relative only**: no leading `/`
|
||||||
- **No parent traversal**: no `..` path segments
|
- **No parent traversal**: no `..` path segments
|
||||||
|
- **No current-directory segments**: no `.` path segments
|
||||||
- **No empty segments**: no `//` sequences
|
- **No empty segments**: no `//` sequences
|
||||||
- **No trailing slash**: paths refer to files, not directories
|
- **No trailing slash**: paths refer to files, not directories
|
||||||
- **Listed once**: each path appears at most once in a manifest, compared byte
|
- **Listed once**: each path appears at most once in a manifest, compared byte
|
||||||
|
|||||||
@@ -1243,10 +1243,10 @@ func TestFetchRequireSignature(t *testing.T) {
|
|||||||
|
|
||||||
// TestFetchRefusesListedManifestName fetches manifests that list, at the
|
// TestFetchRefusesListedManifestName fetches manifests that list, at the
|
||||||
// top of the tree, the name fetch saves the manifest under or that name's
|
// top of the tree, the name fetch saves the manifest under or that name's
|
||||||
// temp file: as a file, as a directory, in capitals, and with a leading
|
// temp file: as a file, as a directory and in capitals. Saving the
|
||||||
// "./". Saving the manifest would replace or remove what is listed there,
|
// manifest would replace or remove what is listed there, so fetch must
|
||||||
// so fetch must refuse the manifest before it creates the destination or
|
// refuse the manifest before it creates the destination or requests any
|
||||||
// requests any file.
|
// file.
|
||||||
func TestFetchRefusesListedManifestName(t *testing.T) {
|
func TestFetchRefusesListedManifestName(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -1255,7 +1255,6 @@ func TestFetchRefusesListedManifestName(t *testing.T) {
|
|||||||
tempPathFor(defaultManifestName),
|
tempPathFor(defaultManifestName),
|
||||||
defaultManifestName + "/" + testFileTxt,
|
defaultManifestName + "/" + testFileTxt,
|
||||||
"INDEX.MF",
|
"INDEX.MF",
|
||||||
"./" + defaultManifestName,
|
|
||||||
} {
|
} {
|
||||||
t.Run(listed, func(t *testing.T) {
|
t.Run(listed, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -1331,9 +1330,9 @@ func TestFetchRefusesListedTempName(t *testing.T) {
|
|||||||
// directory, one of them under a spelling the manifest does not list,
|
// directory, one of them under a spelling the manifest does not list,
|
||||||
// and check reports that file as not in the manifest. So fetch must
|
// and check reports that file as not in the manifest. So fetch must
|
||||||
// refuse each on every filesystem before it creates the destination or
|
// refuse each on every filesystem before it creates the destination or
|
||||||
// requests any file. A file and a directory with the same name, and a
|
// requests any file. A file and a directory with the same name are
|
||||||
// file listed twice, are refused the same way. A manifest whose names
|
// refused the same way. A manifest whose names differ in more than
|
||||||
// differ in more than letter case is fetched in full.
|
// letter case is fetched in full.
|
||||||
func TestFetchRefusesNamesEqualIgnoringCase(t *testing.T) {
|
func TestFetchRefusesNamesEqualIgnoringCase(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -1343,7 +1342,6 @@ func TestFetchRefusesNamesEqualIgnoringCase(t *testing.T) {
|
|||||||
{"Dir", "dir/x", "dir/x (the file Dir)"},
|
{"Dir", "dir/x", "dir/x (the file Dir)"},
|
||||||
{"Dir/a.txt", "dir/b.txt", "dir/b.txt (the directory Dir)"},
|
{"Dir/a.txt", "dir/b.txt", "dir/b.txt (the directory Dir)"},
|
||||||
{"dir", "dir/x", "dir/x (the file dir)"},
|
{"dir", "dir/x", "dir/x (the file dir)"},
|
||||||
{"./x.txt", "x.txt", "x.txt (the file ./x.txt)"},
|
|
||||||
} {
|
} {
|
||||||
t.Run(tc.first+" and "+tc.second, func(t *testing.T) {
|
t.Run(tc.first+" and "+tc.second, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
@@ -1573,8 +1571,7 @@ func manifestWithMode(t *testing.T, path string, content []byte, mode uint32) []
|
|||||||
}
|
}
|
||||||
|
|
||||||
// builtManifest returns a manifest of files, built directly rather than
|
// builtManifest returns a manifest of files, built directly rather than
|
||||||
// scanned, since a scan lists no hidden files and never a path starting
|
// scanned, since a scan lists no hidden files.
|
||||||
// with "./".
|
|
||||||
func builtManifest(t *testing.T, files map[string][]byte) []byte {
|
func builtManifest(t *testing.T, files map[string][]byte) []byte {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ var (
|
|||||||
errPathAbsolute = errors.New("is absolute; must be relative")
|
errPathAbsolute = errors.New("is absolute; must be relative")
|
||||||
errPathEmptySegment = errors.New("contains empty segment")
|
errPathEmptySegment = errors.New("contains empty segment")
|
||||||
errPathDotDot = errors.New("contains '..' segment")
|
errPathDotDot = errors.New("contains '..' segment")
|
||||||
|
errPathDot = errors.New("contains '.' segment")
|
||||||
errSizeMismatch = errors.New("size mismatch")
|
errSizeMismatch = errors.New("size mismatch")
|
||||||
errNegativeSize = errors.New("size cannot be negative")
|
errNegativeSize = errors.New("size cannot be negative")
|
||||||
errHashNotMultihash = errors.New("hash is not a valid multihash")
|
errHashNotMultihash = errors.New("hash is not a valid multihash")
|
||||||
@@ -46,6 +47,7 @@ var (
|
|||||||
// - Must use forward slashes only (no backslashes)
|
// - Must use forward slashes only (no backslashes)
|
||||||
// - Must be relative (no leading /)
|
// - Must be relative (no leading /)
|
||||||
// - Must not contain ".." segments
|
// - Must not contain ".." segments
|
||||||
|
// - Must not contain "." segments
|
||||||
// - Must not contain empty segments (no "//")
|
// - Must not contain empty segments (no "//")
|
||||||
// - Must not be empty
|
// - Must not be empty
|
||||||
func ValidatePath(p string) error {
|
func ValidatePath(p string) error {
|
||||||
@@ -73,6 +75,10 @@ func ValidatePath(p string) error {
|
|||||||
if seg == ".." {
|
if seg == ".." {
|
||||||
return fmt.Errorf("path %q %w", p, errPathDotDot)
|
return fmt.Errorf("path %q %w", p, errPathDotDot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if seg == "." {
|
||||||
|
return fmt.Errorf("path %q %w", p, errPathDot)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -286,6 +286,9 @@ func TestValidatePath(t *testing.T) {
|
|||||||
{"has/../traversal", "dot-dot segment"},
|
{"has/../traversal", "dot-dot segment"},
|
||||||
{"has//double", "empty segment"},
|
{"has//double", "empty segment"},
|
||||||
{"..", "just dot-dot"},
|
{"..", "just dot-dot"},
|
||||||
|
{"./a.txt", "leading dot segment"},
|
||||||
|
{"has/./dot", "interior dot segment"},
|
||||||
|
{".", "just dot"},
|
||||||
{string([]byte{0xff, 0xfe}), "invalid UTF-8"},
|
{string([]byte{0xff, 0xfe}), "invalid UTF-8"},
|
||||||
}
|
}
|
||||||
for _, tt := range invalid {
|
for _, tt := range invalid {
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ func TestDeserializeRejectsInvalidEntryPaths(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"parent traversal", "../escape"},
|
{"parent traversal", "../escape"},
|
||||||
{"interior traversal", "a/../../escape"},
|
{"interior traversal", "a/../../escape"},
|
||||||
|
{"leading dot segment", "./a.txt"},
|
||||||
|
{"interior dot segment", "dir/./a.txt"},
|
||||||
{"absolute path", "/etc/passwd"},
|
{"absolute path", "/etc/passwd"},
|
||||||
{"backslash path", `a\b`},
|
{"backslash path", `a\b`},
|
||||||
{"double slash", "a//b"},
|
{"double slash", "a//b"},
|
||||||
|
|||||||
@@ -62,6 +62,12 @@ func TestValidatePathMessagesVerbatim(t *testing.T) {
|
|||||||
want: `path "a/../b" contains '..' segment`,
|
want: `path "a/../b" contains '..' segment`,
|
||||||
is: errPathDotDot,
|
is: errPathDotDot,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "dot segment",
|
||||||
|
path: "a/./b",
|
||||||
|
want: `path "a/./b" contains '.' segment`,
|
||||||
|
is: errPathDot,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
Reference in New Issue
Block a user