Skip to content

Commit

Permalink
fix (canary): canary cookie compat
Browse files Browse the repository at this point in the history
  • Loading branch information
mickael-kerjean committed Oct 15, 2024
1 parent 363f9bd commit 53b12f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
20 changes: 20 additions & 0 deletions server/common/recovery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package common

import (
"net/http"
)

// previous cookie configuration in canary release of 2024/10 break existing cookie and
// can introduce weird error when a user has things in cache.
// this code will deprecate early 2025
func RecoverFromBadCookie(res http.ResponseWriter) {
http.SetCookie(res, &http.Cookie{
Name: "auth",
Value: "",
MaxAge: -1,
HttpOnly: true,
SameSite: http.SameSiteStrictMode,
Path: WithBase("/api/"),
Secure: false,
})
}
5 changes: 3 additions & 2 deletions server/middleware/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func SessionStart(fn HandlerFunc) HandlerFunc {
}
ctx.Authorization = _extractAuthorization(req)
if ctx.Session, err = _extractSession(req, ctx); err != nil {
RecoverFromBadCookie(res)
SendErrorResult(res, err)
return
}
Expand Down Expand Up @@ -282,7 +283,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
str, err = DecryptString(SECRET_KEY_DERIVATE_FOR_USER, ctx.Share.Auth)
if err != nil {
// This typically happen when changing the secret key
return session, nil
return session, ErrInternal
}
err = json.Unmarshal([]byte(str), &session)
if IsDirectory(ctx.Share.Path) {
Expand Down Expand Up @@ -310,7 +311,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
if err != nil {
// This typically happen when changing the secret key
Log.Debug("middleware::session decrypt error '%s'", err.Error())
return session, nil
return session, ErrInternal
}
if err = json.Unmarshal([]byte(str), &session); err != nil {
return session, err
Expand Down

0 comments on commit 53b12f9

Please sign in to comment.