{"record":{"id":"ad1ccfe608c7d0d4","repo":"fish2018/pansou","slug":"cookie","errorCode":null,"errorMessage":"登录成功但未获取到有效 Cookie","messagePattern":"登录成功但未获取到有效 Cookie","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/panlian/panlian.go","lineNumber":1135,"sourceCode":"\tcancel()\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", nil, fmt.Errorf(\"登录请求失败: HTTP %d\", resp.StatusCode)\n\t}\n\n\tvar loginResp LoginResponse\n\tif err := json.Unmarshal(respBody, &loginResp); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"解析登录响应失败: %w\", err)\n\t}\n\tif !loginResp.Success {\n\t\treturn \"\", nil, errors.New(strings.TrimSpace(loginResp.Message))\n\t}\n\n\tcookieString := cookiesToString(jar.Cookies(baseURL))\n\tif cookieString == \"\" {\n\t\treturn \"\", nil, fmt.Errorf(\"登录成功但未获取到有效 Cookie\")\n\t}\n\n\treturn cookieString, &loginResp, nil\n}\n\nfunc (p *PanlianPlugin) reloginUser(user *User) error {\n\tpassword, err := p.decryptPassword(user.EncryptedPassword)\n\tif err != nil {\n\t\treturn err\n\t}\n\tcookie, _, err := p.doLogin(user.Username, password, true)\n\tif err != nil {\n\t\tuser.Status = \"expired\"\n\t\tuser.Cookie = \"\"\n\t\t_ = p.saveUser(user)\n\t\treturn err\n\t}\n","sourceCodeStart":1117,"sourceCodeEnd":1153,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/panlian/panlian.go#L1117-L1153","documentation":"The login response reported Success=true, but the cookie jar contained no cookies for the base URL, so cookiesToString produced an empty string. Without a cookie the session cannot be reused, so the plugin refuses to return a useless empty credential.","triggerScenarios":"Upstream returns success JSON but sets cookies on a different domain/path than DefaultBaseURL, sets no cookies at all, or cookiejar.New failed silently (error ignored) leaving no jar.","commonSituations":"Site changed cookie domain (e.g. moved to a subdomain); SameSite/secure attribute changes; upstream success response no longer establishes a session cookie.","solutions":["Parse the cookie base URL from the actual login response URL instead of hardcoding DefaultBaseURL","Check the jar error from cookiejar.New instead of discarding it","Inspect Set-Cookie headers of the login response directly as a fallback","Update DefaultBaseURL if the site changed domains"],"exampleFix":"// before\njar, _ := cookiejar.New(nil)\n...\nbaseURL, _ := url.Parse(DefaultBaseURL)\n// after\njar, err := cookiejar.New(nil)\nif err != nil { return \"\", nil, err }\n...\nbaseURL, _ := url.Parse(resp.Request.URL.String())","handlingStrategy":"fallback","validationCode":"if len(resp.Cookies()) == 0 {\n    return errors.New(\"login response carried no Set-Cookie headers\")\n}","typeGuard":null,"tryCatchPattern":"cookieString, loginResp, err := p.doLogin(u, p, true)\nif err != nil {\n    if strings.Contains(err.Error(), \"未获取到有效 Cookie\") {\n        return fmt.Errorf(\"session establishment failed; check cookie domain config: %w\", err)\n    }\n    return err\n}","preventionTips":["Derive the cookie domain from the actual response URL, not a hardcoded base URL","Handle the error from cookiejar.New instead of discarding it","Log Set-Cookie headers during login debugging"],"tags":["cookies","session","login","go"],"backgroundTag":"empty-response-body","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}