From ec6dab2dafbd7f84c89f77a35fed1d5b9d5d891e Mon Sep 17 00:00:00 2001 From: Rishi Balakrishnan Date: Fri, 17 Jul 2026 09:12:27 -0400 Subject: [PATCH] bskyweb: key rate limiter on real client IP behind Cloudflare/DO (#129) --- bskyweb/cmd/bskyweb/server.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index b0f608527..f27faf843 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -217,11 +217,21 @@ func serve(cctx *cli.Context) error { }, ), IdentifierExtractor: func(ctx echo.Context) (string, error) { - id := ctx.RealIP() - return id, nil + // We sit behind Cloudflare and DigitalOcean's load balancer, so the + // socket peer is always an edge IP and ctx.RealIP() alone collapses + // every user into a handful of buckets. Prefer the proxy-supplied + // real-client headers, then fall back to RealIP() (which itself + // checks X-Forwarded-For, then X-Real-IP, then the socket address). + req := ctx.Request() + for _, h := range []string{"CF-Connecting-IP", "True-Client-IP"} { + if ip := req.Header.Get(h); ip != "" { + return ip, nil + } + } + return ctx.RealIP(), nil }, DenyHandler: func(c echo.Context, identifier string, err error) error { - return c.String(http.StatusTooManyRequests, "Your request has been rate limited. Please try again later. Contact security@bsky.app if you believe this was a mistake.\n") + return c.String(http.StatusTooManyRequests, "Your request has been rate limited. Please try again later. Contact support@blacksky.app if you believe this was a mistake.\n") }, })) -- knotmirror 0.0.1