Sign-ins finish only in the browser that started them
A Core sign-in, and a posting account's or Search Console's OAuth sign-in, now sets a short-lived cookie whose hash the flow keeps on the server. The callback refuses one without it (constant-time compare), clears the cookie either way, and the flow is used up regardless. This stops login CSRF: a callback URL brought to another browser signs nobody in. The cookie uses the __Host- prefix over https, so its Path is "/". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -401,6 +401,10 @@ func (s *Server) oauthStart(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
p.For, p.Team = forUser, s.team()
|
||||
if p.Browser, err = s.bindFlow(w, oauthFlowCookie, oauthTTL); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
// Kept in the database: the callback may reach another copy of the app.
|
||||
if err := s.DB.PutJSON(oauthFlowKey+p.State, p); err != nil {
|
||||
s.serverError(w, err)
|
||||
@@ -466,6 +470,16 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
if p != nil && p.For != 0 {
|
||||
back, nav = "/settings/account#posting", "settings/account"
|
||||
}
|
||||
browser := ""
|
||||
if p != nil {
|
||||
browser = p.Browser
|
||||
}
|
||||
// Only in the browser that started it (the cookie is cleared either way).
|
||||
if !s.flowFromThisBrowser(w, r, oauthFlowCookie, browser) {
|
||||
s.Log.Warn("oauth: callback from another browser", "provider", provider)
|
||||
redirect(w, r, back, "oauth-expired")
|
||||
return
|
||||
}
|
||||
if p == nil || p.Provider != provider || time.Since(p.Started) > oauthTTL || (p.Team != 0 && p.Team != s.team()) {
|
||||
s.Log.Warn("oauth: callback with an unknown or expired state", "provider", provider)
|
||||
redirect(w, r, back, "oauth-expired")
|
||||
|
||||
Reference in New Issue
Block a user