From 82e12ca1a6f71909c6bfad5bd5a928d620c86d8a Mon Sep 17 00:00:00 2001 From: Mickael Kerjean Date: Tue, 1 Feb 2022 17:16:21 +1100 Subject: [PATCH] fix (#422): retrocompatibility with authentication middleware --- server/common/utils.go | 8 ++++++++ server/ctrl/session.go | 7 +++---- server/ctrl/share.go | 4 ++-- server/middleware/session.go | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/common/utils.go b/server/common/utils.go index d9ae937b..ff1f5122 100644 --- a/server/common/utils.go +++ b/server/common/utils.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "io/ioutil" + "strconv" ) func NewBool(t bool) *bool { @@ -81,3 +82,10 @@ func PrettyPrint(json_dirty []byte) []byte { json_pretty.Write([]byte("\n")) return json_pretty.Bytes() } + +func CookieName(idx int) string { + if idx == 0 { + return COOKIE_NAME_AUTH + } + return COOKIE_NAME_AUTH + strconv.Itoa(idx) +} diff --git a/server/ctrl/session.go b/server/ctrl/session.go index 462ee89f..7ef85f19 100644 --- a/server/ctrl/session.go +++ b/server/ctrl/session.go @@ -8,7 +8,6 @@ import ( "github.com/mickael-kerjean/filestash/server/model" "net/http" "net/url" - "strconv" "strings" "time" ) @@ -96,7 +95,7 @@ func SessionAuthenticate(ctx App, res http.ResponseWriter, req *http.Request) { end = len(obfuscate) } http.SetCookie(res, &http.Cookie{ - Name: COOKIE_NAME_AUTH + strconv.Itoa(index), + Name: CookieName(index), Value: obfuscate[index*value_limit : end], MaxAge: 60 * Config.Get("general.cookie_timeout").Int(), Path: COOKIE_PATH, @@ -135,12 +134,12 @@ func SessionLogout(ctx App, res http.ResponseWriter, req *http.Request) { }() index := 0 for { - _, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index)) + _, err := req.Cookie(CookieName(index)) if err != nil { break } http.SetCookie(res, &http.Cookie{ - Name: COOKIE_NAME_AUTH + strconv.Itoa(index), + Name: CookieName(index), Value: "", MaxAge: -1, Path: COOKIE_PATH, diff --git a/server/ctrl/share.go b/server/ctrl/share.go index d2f21200..c860e339 100644 --- a/server/ctrl/share.go +++ b/server/ctrl/share.go @@ -7,7 +7,6 @@ import ( . "github.com/mickael-kerjean/filestash/server/common" "github.com/mickael-kerjean/filestash/server/model" "net/http" - "strconv" "strings" ) @@ -45,7 +44,8 @@ func ShareUpsert(ctx App, res http.ResponseWriter, req *http.Request) { str := "" index := 0 for { - cookie, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index)) + + cookie, err := req.Cookie(CookieName(index)) if err != nil { break } diff --git a/server/middleware/session.go b/server/middleware/session.go index 4b9f6337..d91b3b51 100644 --- a/server/middleware/session.go +++ b/server/middleware/session.go @@ -10,7 +10,6 @@ import ( "github.com/mickael-kerjean/filestash/server/model" "net/http" "regexp" - "strconv" "strings" ) @@ -260,7 +259,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) { str := "" index := 0 for { - cookie, err := req.Cookie(COOKIE_NAME_AUTH + strconv.Itoa(index)) + cookie, err := req.Cookie(CookieName(index)) if err != nil { break }