panel: __Host- session cookie and duplicate-cookie detection
Phase 14.B. The cookie already satisfied everything the __Host- prefix requires — Secure, Path=/, no Domain — but as a promise the server makes, not one the browser enforces. With the prefix the browser refuses to store a same-named cookie carrying a Domain attribute, which is the second lever the same-site neighbour from 14.A has: set selfpost_session for the parent domain, and the browser sends two cookies of that name, oldest first. r.Cookie returned that first one, so the admin logged in successfully and landed back on the login form, for as long as the planted cookie lived. The name has to stay conditional: __Host- is only valid on a Secure cookie, so with PANEL_COOKIE_SECURE=false the browser would discard the Set-Cookie and the dev instance would fail to log in with no visible reason. Hence the test on that branch specifically, not just the production one. requireAuth now reads r.Cookies() and refuses a request carrying more than one cookie of the name, with a log line naming the cause. That is the only place the overwrite becomes visible at all, and unlike the prefix it also works in the dev shape. Sign-out clears both names, so the upgrade does not leave the old cookie behind; it does sign the administrator out once, which costs nothing given sessions live in memory and die on restart anyway. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -142,12 +142,12 @@ func (s *Server) submitAccount(w http.ResponseWriter, r *http.Request) {
|
||||
// Keep this session usable under the new name, and — when the password
|
||||
// changed — drop every other session so a cookie captured under the old
|
||||
// password stops working.
|
||||
if c, err := r.Cookie(sessionCookie); err == nil {
|
||||
if token, ok := s.sessionToken(r); ok {
|
||||
if renaming {
|
||||
s.sessions.Rename(c.Value, username)
|
||||
s.sessions.Rename(token, username)
|
||||
}
|
||||
if repassword {
|
||||
s.sessions.DestroyOthers(c.Value)
|
||||
s.sessions.DestroyOthers(token)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user