From 9d61c72427c05e3739f2e4bf3580388d2abfd1a5 Mon Sep 17 00:00:00 2001 From: Dylan-Liew <63992885+Dylan-Liew@users.noreply.github.com> Date: Wed, 7 Oct 2026 15:45:27 +0800 Subject: [PATCH] fix(appstore): use slashed authenticate path from bag --- internal/appstore/bag.go | 16 +++++++++++++--- internal/appstore/client.go | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/appstore/bag.go b/internal/appstore/bag.go index 1337269d1..46c2366b6 100644 --- a/internal/appstore/bag.go +++ b/internal/appstore/bag.go @@ -27,11 +27,11 @@ func (c *Client) bag() (SAPConfig, error) { return SAPConfig{}, err } - url := fmt.Sprintf("https://%s%s?guid=%s", initDomain, initPath, g) + bagURL := fmt.Sprintf("https://%s%s?guid=%s", initDomain, initPath, g) var out bagResult - res, err := c.send(http.MethodGet, url, map[string]string{"Accept": "application/xml"}, nil, nil, formatXML, &out) + res, err := c.send(http.MethodGet, bagURL, map[string]string{"Accept": "application/xml"}, nil, nil, formatXML, &out) if err != nil { return SAPConfig{}, fmt.Errorf("bag: %w", err) } @@ -57,6 +57,16 @@ func (c *Client) bag() (SAPConfig, error) { return SAPConfig{}, fmt.Errorf("bag: %w", err) } + authEndpoint, err := url.Parse(config.AuthEndpoint) + if err != nil { + return SAPConfig{}, fmt.Errorf("bag: parse authentication endpoint: %w", err) + } + + // The bare path returns unusable responses (204/301/HTML); Apple only + // answers the signed authenticate request on the slashed path. + authEndpoint.Path = PrivateAppStoreAPIPathAuth + "/" + config.AuthEndpoint = authEndpoint.String() + return config, nil } @@ -98,7 +108,7 @@ func validateAuthenticationEndpoint(endpoint string) error { return fmt.Errorf("unsupported authentication endpoint %q", endpoint) } - if parsed.Path != PrivateAppStoreAPIPathAuth { + if parsed.Path != PrivateAppStoreAPIPathAuth && parsed.Path != PrivateAppStoreAPIPathAuth+"/" { return fmt.Errorf("unsupported authentication endpoint %q", endpoint) } diff --git a/internal/appstore/client.go b/internal/appstore/client.go index c172e3c65..c1506a02e 100644 --- a/internal/appstore/client.go +++ b/internal/appstore/client.go @@ -24,7 +24,7 @@ func New(cookiesFile string) (*Client, error) { hc := &http.Client{ Jar: jar, CheckRedirect: func(req *http.Request, via []*http.Request) error { - if req.Referer() == authURL { + if strings.TrimSuffix(req.Referer(), "/") == authURL { return http.ErrUseLastResponse }