Skip to content

Commit 53b12f9

Browse files
fix (canary): canary cookie compat
1 parent 363f9bd commit 53b12f9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

server/common/recovery.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package common
2+
3+
import (
4+
"net/http"
5+
)
6+
7+
// previous cookie configuration in canary release of 2024/10 break existing cookie and
8+
// can introduce weird error when a user has things in cache.
9+
// this code will deprecate early 2025
10+
func RecoverFromBadCookie(res http.ResponseWriter) {
11+
http.SetCookie(res, &http.Cookie{
12+
Name: "auth",
13+
Value: "",
14+
MaxAge: -1,
15+
HttpOnly: true,
16+
SameSite: http.SameSiteStrictMode,
17+
Path: WithBase("/api/"),
18+
Secure: false,
19+
})
20+
}

server/middleware/session.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func SessionStart(fn HandlerFunc) HandlerFunc {
6060
}
6161
ctx.Authorization = _extractAuthorization(req)
6262
if ctx.Session, err = _extractSession(req, ctx); err != nil {
63+
RecoverFromBadCookie(res)
6364
SendErrorResult(res, err)
6465
return
6566
}
@@ -282,7 +283,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
282283
str, err = DecryptString(SECRET_KEY_DERIVATE_FOR_USER, ctx.Share.Auth)
283284
if err != nil {
284285
// This typically happen when changing the secret key
285-
return session, nil
286+
return session, ErrInternal
286287
}
287288
err = json.Unmarshal([]byte(str), &session)
288289
if IsDirectory(ctx.Share.Path) {
@@ -310,7 +311,7 @@ func _extractSession(req *http.Request, ctx *App) (map[string]string, error) {
310311
if err != nil {
311312
// This typically happen when changing the secret key
312313
Log.Debug("middleware::session decrypt error '%s'", err.Error())
313-
return session, nil
314+
return session, ErrInternal
314315
}
315316
if err = json.Unmarshal([]byte(str), &session); err != nil {
316317
return session, err

0 commit comments

Comments
 (0)