diff --git a/server/common/crypto.go b/server/common/crypto.go index 394f5203..da7e47ed 100644 --- a/server/common/crypto.go +++ b/server/common/crypto.go @@ -191,11 +191,10 @@ func verify(something []byte) ([]byte, error) { } // Create a unique ID that can be use to identify different session -func GenerateID(ctx *App) string { +func GenerateID(params map[string]string) string { p := "" - - orderedKeys := make([]string, len(ctx.Session)) - for key, _ := range ctx.Session { + orderedKeys := make([]string, len(params)) + for key, _ := range params { orderedKeys = append(orderedKeys, key) } sort.Strings(orderedKeys) @@ -206,8 +205,8 @@ func GenerateID(ctx *App) string { case "password": case "path": default: - if val := ctx.Session[key]; val != "" { - p += key + "=>" + ctx.Session[key] + ", " + if val := params[key]; val != "" { + p += key + "=>" + params[key] + ", " } } } diff --git a/server/ctrl/session.go b/server/ctrl/session.go index e97230b8..99e904f4 100644 --- a/server/ctrl/session.go +++ b/server/ctrl/session.go @@ -43,7 +43,7 @@ func SessionGet(ctx *App, res http.ResponseWriter, req *http.Request) { } r.IsAuth = true r.Home = NewString(home) - r.Backend = GenerateID(ctx) + r.Backend = GenerateID(ctx.Session) if ctx.Share.Id == "" && Config.Get("features.protection.enable_chromecast").Bool() { r.Authorization = ctx.Authorization } diff --git a/server/ctrl/share.go b/server/ctrl/share.go index 01798eff..64c5b367 100644 --- a/server/ctrl/share.go +++ b/server/ctrl/share.go @@ -17,7 +17,7 @@ func ShareList(ctx *App, res http.ResponseWriter, req *http.Request) { return } listOfSharedLinks, err := model.ShareList( - GenerateID(ctx), + GenerateID(ctx.Session), path, ) if err != nil { @@ -59,7 +59,7 @@ func ShareUpsert(ctx *App, res http.ResponseWriter, req *http.Request) { }(), Backend: func() string { if ctx.Share.Id == "" { - return GenerateID(ctx) + return GenerateID(ctx.Session) } return ctx.Share.Backend }(), diff --git a/server/middleware/session.go b/server/middleware/session.go index c0f72f34..511e9e7c 100644 --- a/server/middleware/session.go +++ b/server/middleware/session.go @@ -137,7 +137,7 @@ func CanManageShare(fn HandlerFunc) HandlerFunc { SendErrorResult(res, err) return } - if s.Backend == GenerateID(ctx) { + if s.Backend == GenerateID(ctx.Session) { fn(ctx, res, req) return } @@ -155,7 +155,7 @@ func CanManageShare(fn HandlerFunc) HandlerFunc { return } - id := GenerateID(ctx) + id := GenerateID(ctx.Session) if s.Backend == id { if s.CanShare == true { fn(ctx, res, req) diff --git a/server/middleware/telemetry.go b/server/middleware/telemetry.go index b7e49500..c7c5b7cf 100644 --- a/server/middleware/telemetry.go +++ b/server/middleware/telemetry.go @@ -67,7 +67,7 @@ func logger(ctx App, res http.ResponseWriter, req *http.Request) { if ctx.Session["type"] == "" { return "null" } - return GenerateID(&ctx) + return GenerateID(ctx.Session) }(), RequestID: func() string { defer func() string { diff --git a/server/plugin/plg_backend_git/index.go b/server/plugin/plg_backend_git/index.go index 1a315054..b2b2d0bb 100644 --- a/server/plugin/plg_backend_git/index.go +++ b/server/plugin/plg_backend_git/index.go @@ -88,7 +88,7 @@ func (git Git) Init(params map[string]string, app *App) (IBackend, error) { p.committerEmail = "https://filestash.app" } - hash := GenerateID(app) + hash := GenerateID(params) p.basePath = GetAbsolutePath( TMP_PATH, "git_"+hash, diff --git a/server/plugin/plg_editor_onlyoffice/index.go b/server/plugin/plg_editor_onlyoffice/index.go index a58681d5..92548a33 100644 --- a/server/plugin/plg_editor_onlyoffice/index.go +++ b/server/plugin/plg_editor_onlyoffice/index.go @@ -196,7 +196,7 @@ func IframeContentHandler(ctx *App, res http.ResponseWriter, req *http.Request) return } - userId = GenerateID(ctx) + userId = GenerateID(ctx.Session) f, err := ctx.Backend.Cat(path) if err != nil { SendErrorResult(res, err) diff --git a/server/plugin/plg_video_transcoder/index.go b/server/plugin/plg_video_transcoder/index.go index 9e505898..59f9282f 100644 --- a/server/plugin/plg_video_transcoder/index.go +++ b/server/plugin/plg_video_transcoder/index.go @@ -131,7 +131,7 @@ func hls_playlist(reader io.ReadCloser, ctx *App, res *http.ResponseWriter, req return reader, nil } - cacheName := "vid_" + GenerateID(ctx) + "_" + QuickHash(path, 10) + ".dat" + cacheName := "vid_" + GenerateID(ctx.Session) + "_" + QuickHash(path, 10) + ".dat" cachePath := GetAbsolutePath( VideoCachePath, cacheName,