From 90b6e4f5ce1efdb2a860ee47cc49e36a4bdb7b14 Mon Sep 17 00:00:00 2001 From: Christ Date: Sun, 26 Jul 2026 00:03:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BB=AD=E6=9C=9F):=20=E8=AF=86=E5=88=AB?= =?UTF-8?q?=20HttpOnly=20=E9=95=BF=E7=99=BB=E5=BD=95=E5=87=AD=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/xianyu/renew/service.go | 11 ++++------- internal/xianyu/renew/service_test.go | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/internal/xianyu/renew/service.go b/internal/xianyu/renew/service.go index c9a25d8..992c213 100644 --- a/internal/xianyu/renew/service.go +++ b/internal/xianyu/renew/service.go @@ -354,13 +354,10 @@ func (s Service) RenewAPIFirst(ctx context.Context, cookiesStr string, snapshots var snapshot []cookierefresh.BrowserCookie if authoritativeSnapshot { snapshot = cookierefresh.NormalizeSnapshot(snapshots[0]) - documentCookies := make([]cookierefresh.BrowserCookie, 0, len(snapshot)) - for _, cookie := range snapshot { - if !cookie.HTTPOnly { - documentCookies = append(documentCookies, cookie) - } - } - if scoped, authoritative := cookierefresh.ScopedCookieHeaderForRequest(documentCookies, documentURL, goofishTopSite, now); authoritative { + // havana_lgc_exp 由官网以 HttpOnly Cookie 下发。续期服务保存的是 + // 浏览器完整 Cookie Jar,不能按 document.cookie 过滤,否则刚登录的 + // 有效长登录凭证会被误判为不存在。 + if scoped, authoritative := cookierefresh.ScopedCookieHeaderForRequest(snapshot, documentURL, goofishTopSite, now); authoritative { decisionCookies = scoped } if scoped, authoritative := cookierefresh.ScopedCookieHeaderForRequest(snapshot, requestURL, goofishTopSite, now); authoritative { diff --git a/internal/xianyu/renew/service_test.go b/internal/xianyu/renew/service_test.go index 4d6291e..0579e30 100644 --- a/internal/xianyu/renew/service_test.go +++ b/internal/xianyu/renew/service_test.go @@ -315,7 +315,7 @@ func TestRenewAPIFirstUsesBrowserCookieScopes(t *testing.T) { host := strings.TrimPrefix(srv.URL, "http://") host = strings.Split(host, ":")[0] snapshot := []cookierefresh.BrowserCookie{ - {Name: "havana_lgc_exp", Value: futureMillis(time.Hour), Domain: ".goofish.com", Path: "/"}, + {Name: "havana_lgc_exp", Value: futureMillis(time.Hour), Domain: ".goofish.com", Path: "/", HTTPOnly: true}, {Name: "request_only", Value: "passport", Domain: host, Path: "/"}, {Name: "www_only", Value: "private", Domain: "www.goofish.com", Path: "/im"}, {Name: "http_only_document", Value: "hidden", Domain: ".goofish.com", Path: "/", HTTPOnly: true}, @@ -333,6 +333,24 @@ func TestRenewAPIFirstUsesBrowserCookieScopes(t *testing.T) { } } +func TestRenewAPIFirstUsesHTTPOnlyLongLoginCookieForDecision(t *testing.T) { + useTestDesktopFingerprint(t) + var calls atomic.Int32 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + calls.Add(1) + _, _ = w.Write([]byte(`{"data":{"content":{"data":{"processFinished":true,"resultCode":100}}}}`)) + })) + defer srv.Close() + snapshot := []cookierefresh.BrowserCookie{{ + Name: "havana_lgc_exp", Value: futureMillis(time.Hour), Domain: ".goofish.com", Path: "/", HTTPOnly: true, + }} + svc := Service{HTTPClient: srv.Client(), SilentHasLoginURL: srv.URL, RetryDelay: -1} + res, err := svc.RenewAPIFirst(context.Background(), "", snapshot) + if err != nil || res == nil || !res.Success || res.Skipped || res.RequestCount != 1 || calls.Load() != 1 { + t.Fatalf("result=%+v calls=%d err=%v", res, calls.Load(), err) + } +} + func TestRenewAPIFirstRunsWithLinuxChromiumFingerprint(t *testing.T) { fingerprint := useTestLinuxFingerprint(t) var calls atomic.Int32