Skip to content

[transfermanager] Allow downloading directories that contain filenames with double dots - #3396

Open
PolovinaD wants to merge 4 commits into
aws:mainfrom
PolovinaD:fix/download-dir-double-dot-check
Open

[transfermanager] Allow downloading directories that contain filenames with double dots#3396
PolovinaD wants to merge 4 commits into
aws:mainfrom
PolovinaD:fix/download-dir-double-dot-check

Conversation

@PolovinaD

Copy link
Copy Markdown

Summary

Fix overly strict path traversal check in DownloadDirectory.

Problem

The current implementation uses:
strings.Contains(relPath, "..")

This incorrectly rejects valid filenames such as:

  • file..txt

Solution

Replace with:
!filepath.IsLocal(relPath)

This:

  • still prevents traversal (../)
  • allows valid filenames containing '..'

Test

Updated TestDownloadDirectory to verify files with '..' in their names are allowed.
All unit tests pass.

@PolovinaD
PolovinaD requested a review from a team as a code owner April 23, 2026 08:55
@PolovinaD

Copy link
Copy Markdown
Author

Just following up on this PR.

I've been using this change in production via the forked module and it has worked well so far. The workaround is manageable, but I'd like to simplify future SDK upgrades by returning to the upstream module.

This also resolves an upload/download asymmetry where object keys containing .. can be uploaded but can't be downloaded.

Happy to make any changes or add more tests if needed.

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

@wty-Bryant
wty-Bryant force-pushed the fix/download-dir-double-dot-check branch from 305a122 to 0fec8c2 Compare June 4, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants