Cleanup safe path setting location

This commit is contained in:
Zoe Roux 2024-06-09 16:42:56 +02:00
parent ed69bff645
commit e5e98f7fc8
No known key found for this signature in database
2 changed files with 3 additions and 3 deletions

View File

@ -14,6 +14,7 @@ type SettingsT struct {
Outpath string Outpath string
Metadata string Metadata string
RoutePrefix string RoutePrefix string
SafePath string
HwAccel HwAccelT HwAccel HwAccelT
} }
@ -28,5 +29,6 @@ var Settings = SettingsT{
Outpath: GetEnvOr("GOCODER_CACHE_ROOT", "/cache"), Outpath: GetEnvOr("GOCODER_CACHE_ROOT", "/cache"),
Metadata: GetEnvOr("GOCODER_METADATA_ROOT", "/metadata"), Metadata: GetEnvOr("GOCODER_METADATA_ROOT", "/metadata"),
RoutePrefix: GetEnvOr("GOCODER_PREFIX", ""), RoutePrefix: GetEnvOr("GOCODER_PREFIX", ""),
SafePath: GetEnvOr("GOCODER_SAFE_PATH", "/video"),
HwAccel: DetectHardwareAccel(), HwAccel: DetectHardwareAccel(),
} }

View File

@ -14,8 +14,6 @@ import (
"github.com/zoriya/kyoo/transcoder/src" "github.com/zoriya/kyoo/transcoder/src"
) )
var safe_path = src.GetEnvOr("GOCODER_SAFE_PATH", "/video")
// Encode the version in the hash path to update cached values. // Encode the version in the hash path to update cached values.
// Older versions won't be deleted (needed to allow multiples versions of the transcoder to run at the same time) // Older versions won't be deleted (needed to allow multiples versions of the transcoder to run at the same time)
// If the version changes a lot, we might want to automatically delete older versions. // If the version changes a lot, we might want to automatically delete older versions.
@ -34,7 +32,7 @@ func GetPath(c echo.Context) (string, string, error) {
if !filepath.IsAbs(path) { if !filepath.IsAbs(path) {
return "", "", echo.NewHTTPError(http.StatusBadRequest, "Absolute path required.") return "", "", echo.NewHTTPError(http.StatusBadRequest, "Absolute path required.")
} }
if !strings.HasPrefix(path, safe_path) { if !strings.HasPrefix(path, src.Settings.SafePath) {
return "", "", echo.NewHTTPError(http.StatusBadRequest, "Selected path is not marked as safe.") return "", "", echo.NewHTTPError(http.StatusBadRequest, "Selected path is not marked as safe.")
} }
hash, err := getHash(path) hash, err := getHash(path)