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
7 changes: 6 additions & 1 deletion filesystemserver/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
)

type FilesystemHandler struct {
Expand Down Expand Up @@ -33,7 +34,11 @@ func NewFilesystemHandler(allowedDirs []string) (*FilesystemHandler, error) {

// Ensure the path ends with a separator to prevent prefix matching issues
// For example, /tmp/foo should not match /tmp/foobar
normalized = append(normalized, filepath.Clean(abs)+string(filepath.Separator))
cleanPath := filepath.Clean(abs)
if !strings.HasSuffix(cleanPath, string(filepath.Separator)) {
cleanPath = cleanPath + string(filepath.Separator)
}
normalized = append(normalized, cleanPath)
}
return &FilesystemHandler{
allowedDirs: normalized,
Expand Down
13 changes: 13 additions & 0 deletions filesystemserver/handler/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package handler

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestRoot(t *testing.T) {
handler, err := NewFilesystemHandler([]string{"/"})
assert.NoError(t, err)
assert.True(t, handler.isPathInAllowedDirs("/etc/hostname"))
}