summaryrefslogtreecommitdiff
path: root/contrib/fs
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/fs')
-rw-r--r--contrib/fs/dir.go11
-rw-r--r--contrib/fs/file.go14
-rw-r--r--contrib/fs/testdata/.secret-dir/public-file0
-rw-r--r--contrib/fs/testdata/.secret-file0
4 files changed, 25 insertions, 0 deletions
diff --git a/contrib/fs/dir.go b/contrib/fs/dir.go
index bb2d933..69d17e9 100644
--- a/contrib/fs/dir.go
+++ b/contrib/fs/dir.go
@@ -24,6 +24,10 @@ func ResolveDirectory(
path = "."
}
+ if isPrivate(path) {
+ return "", nil, nil
+ }
+
file, err := fileSystem.Open(path)
if isNotFound(err) {
return "", nil, nil
@@ -124,6 +128,13 @@ func dirlistNamespace(path string, dirFile fs.ReadDirFile, server sr.Server) (ma
return nil, err
}
+ for i := len(entries) - 1; i >= 0; i-- {
+ if strings.HasPrefix(entries[i].Name(), ".") {
+ copy(entries[i:], entries[i+1:])
+ entries = entries[:len(entries)-1]
+ }
+ }
+
sort.Slice(entries, func(i, j int) bool {
return entries[i].Name() < entries[j].Name()
})
diff --git a/contrib/fs/file.go b/contrib/fs/file.go
index 591c1bd..d231466 100644
--- a/contrib/fs/file.go
+++ b/contrib/fs/file.go
@@ -15,6 +15,11 @@ import (
// returned.
func ResolveFile(request *sr.Request, fileSystem fs.FS) (string, fs.File, error) {
filepath := strings.TrimPrefix(request.Path, "/")
+
+ if isPrivate(filepath) {
+ return "", nil, nil
+ }
+
file, err := fileSystem.Open(filepath)
if isNotFound(err) {
return "", nil, nil
@@ -57,3 +62,12 @@ func mediaType(filePath string) string {
}
return mtype
}
+
+func isPrivate(fullpath string) bool {
+ for _, segment := range strings.Split(fullpath, "/") {
+ if len(segment) > 1 && segment[0] == '.' {
+ return true
+ }
+ }
+ return false
+}
diff --git a/contrib/fs/testdata/.secret-dir/public-file b/contrib/fs/testdata/.secret-dir/public-file
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/contrib/fs/testdata/.secret-dir/public-file
diff --git a/contrib/fs/testdata/.secret-file b/contrib/fs/testdata/.secret-file
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/contrib/fs/testdata/.secret-file