Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changelog/1c88b192e747436c998a32096006308c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "1c88b192-e747-436c-998a-32096006308c",
"type": "bugfix",
"description": "Loose download directory check to allow downloading objects with double dot in filename",
"modules": [
"feature/s3/transfermanager"
]
}
2 changes: 1 addition & 1 deletion feature/s3/transfermanager/api_op_DownloadDirectory.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (d *directoryDownloader) getLocalPath(key string) (string, error) {
if err != nil {
return "", err
}
if relPath == "." || strings.Contains(relPath, "..") {
if relPath == "." || !filepath.IsLocal(relPath) {
return "", fmt.Errorf("resolved local path %s is outside of destination %s", path, destination)
}

Expand Down
40 changes: 40 additions & 0 deletions feature/s3/transfermanager/download_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,46 @@ func TestDownloadDirectory(t *testing.T) {
l.expectFailed(t, in, err)
},
},
"object key with double dots in name and path": {
destination: "double-dots-in-name-and-path",
objectsLists: [][]s3types.Object{
{
{
Key: aws.String("foo/bar/../baz..zoo"),
},
{
Key: aws.String("a..b"),
},
},
},
expectTokens: []string{""},
expectKeys: []string{"foo/bar/../baz..zoo", "a..b"},
expectFiles: []string{"foo/baz..zoo", "a..b"},
expectObjectsDownloaded: 2,
listenerValidationFn: func(t *testing.T, l *mockDirectoryListener, in, out any, err error) {
l.expectStart(t, in)
l.expectComplete(t, in, out, 2)
},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to add other 2 cases combining path escaping :

"object key with double dots in name and path": {
			destination: "double-dots-in-name-and-path",
			objectsLists: [][]s3types.Object{
				{
					{
						Key: aws.String("foo/bar/../baz..zoo"),
					},
					{
						Key: aws.String("a..b"),
					},
				},
			},
			expectTokens:            []string{""},
			expectKeys:              []string{"foo/bar/../baz..zoo", "a..b"},
			expectFiles:             []string{"foo/baz..zoo", "a..b"},
			expectObjectsDownloaded: 2,
			listenerValidationFn: func(t *testing.T, l *mockDirectoryListener, in, out any, err error) {
				l.expectStart(t, in)
				l.expectComplete(t, in, out, 2)
			},
		},
"object key with double dots in name and path escaping": {
		destination: "double-dots-in-name-and-path-escaping",
			objectsLists: [][]s3types.Object{
				{
					{
						Key: aws.String("foo/../../baz..zoo"),
					},
					{
						Key: aws.String("a..b"),
					},
				},
			},
			expectErr: "outside of destination",
			listenerValidationFn: func(t *testing.T, l *mockDirectoryListener, in, out any, err error) {
				// only validate failure listener since start listener
				// might never be triggerred if the error response is returned first
				l.expectFailed(t, in, err)
			},
		},

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense. I thought it was (partially) covered in error when path resolved from objects key out of destination scope above, but this is definitely more thorough. I updated it

"object key with double dots in name and path escaping": {
destination: "double-dots-in-name-and-path-escaping",
objectsLists: [][]s3types.Object{
{
{
Key: aws.String("foo/../../baz..zoo"),
},
{
Key: aws.String("a..b"),
},
},
},
expectErr: "outside of destination",
listenerValidationFn: func(t *testing.T, l *mockDirectoryListener, in, out any, err error) {
// only validate failure listener since start listener
// might never be triggerred if the error response is returned first
l.expectFailed(t, in, err)
},
},
"multiple objects with filter applied": {
destination: "multiple-objects-with-filter-applied",
objectsLists: [][]s3types.Object{
Expand Down
Loading