mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 22:49:25 +08:00
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:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user