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:
@@ -351,6 +351,10 @@ func (s *Server) signinCore(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
f.Next = next
|
||||
if f.Browser, err = s.bindFlow(w, coreFlowCookie, coreFlowTTL); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
}
|
||||
if err := ts.DB.PutJSON(coreFlowKey+f.State, f); err != nil {
|
||||
s.serverError(w, err)
|
||||
return
|
||||
@@ -374,6 +378,13 @@ func (s *Server) takeCoreFlow(state string) *oidc.Flow {
|
||||
return &f
|
||||
}
|
||||
|
||||
func flowBrowser(f *oidc.Flow) string {
|
||||
if f == nil {
|
||||
return ""
|
||||
}
|
||||
return f.Browser
|
||||
}
|
||||
|
||||
// coreCallbackPage finishes a sign-in with the Core.
|
||||
func (s *Server) coreCallbackPage(w http.ResponseWriter, r *http.Request) {
|
||||
if !s.signsIn() {
|
||||
@@ -401,7 +412,9 @@ func (s *Server) coreCallbackPage(w http.ResponseWriter, r *http.Request) {
|
||||
s.signinFail(w, r, signinForm{Problem: msg}, code)
|
||||
}
|
||||
f := ts.takeCoreFlow(state)
|
||||
if f == nil {
|
||||
// Taken either way, and the cookie cleared: a callback opened in
|
||||
// another browser can't sign it in, nor be tried again.
|
||||
if fromHere := s.flowFromThisBrowser(w, r, coreFlowCookie, flowBrowser(f)); f == nil || !fromHere {
|
||||
fail("That sign-in took too long or was already used. Try again.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user