Skip to content

Modern Docker Management, Designed for Everyone

fix: allow both http and https cookie names

Kyle Mendellb3b9f7159ed5
diff --git a/backend/internal/middleware/auth_middleware.go b/backend/internal/middleware/auth_middleware.go
index 30e26eca6..db5011114 100644
--- a/backend/internal/middleware/auth_middleware.go
+++ b/backend/internal/middleware/auth_middleware.go
@@ -162,8 +162,8 @@ func extractBearerOrCookieToken(c *gin.Context) string {
if strings.HasPrefix(authHeader, "Bearer ") {
return strings.TrimPrefix(authHeader, "Bearer ")
}
- if tokenCookie, err := c.Cookie(cookie.TokenCookieName); err == nil && tokenCookie != "" {
- return tokenCookie
+ if tok, err := cookie.GetTokenCookie(c); err == nil && tok != "" {
+ return tok
}
return ""
}
diff --git a/backend/internal/utils/cookie/cookie_util.go b/backend/internal/utils/cookie/cookie_util.go
index 30f52157a..3db0187b8 100644
--- a/backend/internal/utils/cookie/cookie_util.go
+++ b/backend/internal/utils/cookie/cookie_util.go
@@ -7,19 +7,41 @@ import (
)
var (
- TokenCookieName = "__Host-token" // #nosec G101: cookie name label, not a credential
- OidcStateCookieName = "oidc_state"
+ TokenCookieName = "__Host-token" // #nosec G101: cookie name label, not a credential
+ InsecureTokenCookieName = "token" // #nosec G101: cookie name label, not a credential
+ OidcStateCookieName = "oidc_state"
)
+func isSecure(c *gin.Context) bool {
+ return c.Request.TLS != nil
+}
+
+func tokenCookieName(c *gin.Context) string {
+ if isSecure(c) {
+ return TokenCookieName
+ }
+ return InsecureTokenCookieName
+}
+
func CreateTokenCookie(c *gin.Context, maxAgeInSeconds int, token string) {
if maxAgeInSeconds < 0 {
maxAgeInSeconds = 0
}
- c.SetCookie(TokenCookieName, token, maxAgeInSeconds, "/", "", c.Request.TLS != nil, true)
+ name := tokenCookieName(c)
+ c.SetCookie(name, token, maxAgeInSeconds, "/", "", isSecure(c), true)
}
func ClearTokenCookie(c *gin.Context) {
- c.SetCookie(TokenCookieName, "", -1, "/", "", c.Request.TLS != nil, true)
+ name := tokenCookieName(c)
+ c.SetCookie(name, "", -1, "/", "", isSecure(c), true)
+}
+
+func GetTokenCookie(c *gin.Context) (string, error) {
+ // Try secure name first, then fallback to insecure
+ if v, err := c.Cookie(TokenCookieName); err == nil {
+ return v, nil
+ }
+ return c.Cookie(InsecureTokenCookieName)
}
func CreateOidcStateCookie(c *gin.Context, value string, maxAgeInSeconds int) {