fix(publicip/api/cloudflare): add Referer header (#3058)

This commit is contained in:
Jeremy Lin
2025-12-23 19:52:25 -08:00
committed by GitHub
parent 666f55767b
commit 6eb511fb2a
+3 -1
View File
@@ -40,7 +40,8 @@ func (c *cloudflare) Token() (token string) {
func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) ( func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) (
result models.PublicIP, err error, result models.PublicIP, err error,
) { ) {
url := "https://speed.cloudflare.com/meta" urlBase := "https://speed.cloudflare.com"
url := urlBase + "/meta"
if ip.IsValid() { if ip.IsValid() {
return result, fmt.Errorf("%w: cloudflare cannot provide information on the arbitrary IP address %s", return result, fmt.Errorf("%w: cloudflare cannot provide information on the arbitrary IP address %s",
ErrServiceLimited, ip) ErrServiceLimited, ip)
@@ -50,6 +51,7 @@ func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) (
if err != nil { if err != nil {
return result, err return result, err
} }
request.Header.Add("Referer", urlBase) // returns HTTP 403 otherwise
response, err := c.client.Do(request) response, err := c.client.Do(request)
if err != nil { if err != nil {