From 60f32eb1ddc254d3f6af98ec8fd4997e1a2cdff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 29 Aug 2023 23:47:52 +0200 Subject: [PATCH] Improve path sanitization. --- helpers/settings.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/helpers/settings.go b/helpers/settings.go index 2d79000..7fadde4 100644 --- a/helpers/settings.go +++ b/helpers/settings.go @@ -54,20 +54,19 @@ func SettingsPaths() ([]string, fs.FS, error) { } // we set the main root from the path root - mainRoot = root + "/" + mainRoot = root + // we replace the slashes value = filepath.ToSlash(value) + // we remove the volume or root part (e.g. 'c:/' on Windows or '/' on Linux) value = value[len(root)+1:] - sanitizedValues = append(sanitizedValues, value) - } - // on Linux, mainRoot will be unset - if mainRoot == "" { - mainRoot = "/" + // we append the value to the sanitized paths + sanitizedValues = append(sanitizedValues, value) } - return sanitizedValues, os.DirFS(mainRoot), nil + return sanitizedValues, os.DirFS(mainRoot + "/"), nil } func Settings(settingsPaths []string, fS fs.FS) (kodex.Settings, error) {