From b2f47f8e53739e0b5e9fc33dcb4b7549f8e51708 Mon Sep 17 00:00:00 2001 From: spiral Date: Sun, 19 Mar 2023 14:17:03 -0400 Subject: [PATCH] fix(api): temporarily use custom client-ip header for ratelimiting --- services/api/src/middleware/ratelimit.rs | 2 +- services/web-proxy/main.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/services/api/src/middleware/ratelimit.rs b/services/api/src/middleware/ratelimit.rs index ceec27e3..0c7f4412 100644 --- a/services/api/src/middleware/ratelimit.rs +++ b/services/api/src/middleware/ratelimit.rs @@ -62,7 +62,7 @@ pub async fn do_request_ratelimited( ) -> Response { if let Some(redis) = redis { let headers = request.headers().clone(); - let source_ip = header_or_unknown(headers.get("Fly-Client-IP")); + let source_ip = header_or_unknown(headers.get("X-PluralKit-Client-IP")); // https://github.com/rust-lang/rust/issues/53667 let (rl_key, rate) = if let Some(header) = request.headers().clone().get("X-PluralKit-App") diff --git a/services/web-proxy/main.go b/services/web-proxy/main.go index 7ab6e54b..b8c5d971 100644 --- a/services/web-proxy/main.go +++ b/services/web-proxy/main.go @@ -37,6 +37,9 @@ func (p ProxyHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { return } + r.Header.Del("X-PluralKit-Client-IP") + r.Header.Set("X-PluralKit-Client-IP", r.Header.Get("Fly-Client-IP")) + startTime := time.Now() r = r.WithContext(context.WithValue(r.Context(), "req-time", startTime))