diff --git a/commands.go b/commands.go index 30b0f17..338810e 100644 --- a/commands.go +++ b/commands.go @@ -174,6 +174,9 @@ func fnLoginGoogleCookies(ce *WrappedCommandEvent) { if err != nil { ce.Reply("Failed to parse cookies: %v", err) return + } else if missingCookie := findMissingCookies(cookies); missingCookie != "" { + ce.Reply("Missing %s cookie", missingCookie) + return } ce.Redact() err = ce.User.LoginGoogle(ce.Ctx, cookies, func(emoji string) { diff --git a/provisioning.go b/provisioning.go index cfafcda..e5d3412 100644 --- a/provisioning.go +++ b/provisioning.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http" _ "net/http/pprof" "strings" @@ -321,6 +322,15 @@ type RespGoogleLoginStart struct { Emoji string `json:"emoji"` } +func findMissingCookies(cookies map[string]string) string { + for _, requiredCookie := range []string{"SID", "SSID", "HSID", "OSID", "APISID", "SAPISID"} { + if _, ok := cookies[requiredCookie]; !ok { + return requiredCookie + } + } + return "" +} + func (prov *ProvisioningAPI) GoogleLoginStart(w http.ResponseWriter, r *http.Request) { userID := r.URL.Query().Get("user_id") user := prov.bridge.GetUserByMXID(id.UserID(userID)) @@ -339,6 +349,20 @@ func (prov *ProvisioningAPI) GoogleLoginStart(w http.ResponseWriter, r *http.Req ErrCode: "bad json", }) return + } else if len(req.Cookies) == 0 { + log.Warn().Msg("No cookies in request") + jsonResponse(w, http.StatusBadRequest, Error{ + Error: "No cookies in request", + ErrCode: "missing cookies", + }) + return + } else if missingCookie := findMissingCookies(req.Cookies); missingCookie != "" { + log.Warn().Msg("Missing cookies in request") + jsonResponse(w, http.StatusBadRequest, Error{ + Error: fmt.Sprintf("Missing %s cookie", missingCookie), + ErrCode: "missing cookies", + }) + return } emoji, err := user.AsyncLoginGoogleStart(req.Cookies) if err != nil {