Plugins: Fix files with two dots in the name not being returned by LocalFS.Files() (#67395)

* Fix files with two dots in the name not being returned by LocalFS.Files()

* Renamed variable for consistency

* Add test

* Fix typo

* Fix wrong upperLevelPrefix value

* Removed unnecessary check in LocalFS.Files()
This commit is contained in:
Giuseppe Guerra
2023-04-27 16:19:13 +02:00
committed by GitHub
parent 4b241311b3
commit 7c5210a915
2 changed files with 27 additions and 3 deletions

View File

@ -277,3 +277,26 @@ func TestStaticFS(t *testing.T) {
})
})
}
// TestFSTwoDotsInFileName ensures that LocalFS and StaticFS allow two dots in file names.
// This makes sure that FSes do not believe that two dots in a file name (anywhere in the path)
// represent a path traversal attempt.
func TestFSTwoDotsInFileName(t *testing.T) {
tmp := t.TempDir()
const fn = "test..png"
require.NoError(t, createDummyTempFile(tmp, fn))
localFS := NewLocalFS(tmp)
staticFS, err := NewStaticFS(localFS)
require.NoError(t, err)
// Test both with localFS and staticFS
files, err := localFS.Files()
require.NoError(t, err)
require.Equal(t, []string{"test..png"}, files)
files, err = staticFS.Files()
require.NoError(t, err)
require.Equal(t, []string{"test..png"}, files)
}