From 7a34038102d50adc379cc78d64c5b499720caecd Mon Sep 17 00:00:00 2001 From: amtins Date: Thu, 14 Nov 2024 18:38:19 +0100 Subject: [PATCH] feat(event-receiver): handle X-Forwarded-For header Update IP address extraction to prioritize the `X-Forwarded-For` header. - Fallback to `RemoteAddr` if `X-Forwarded-For` is not present. --- api/handler/handlers.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/handler/handlers.go b/api/handler/handlers.go index f8d5eed..6e4a609 100644 --- a/api/handler/handlers.go +++ b/api/handler/handlers.go @@ -37,7 +37,11 @@ func EventReceiver(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") - ip := r.RemoteAddr + ip := r.Header.Get("X-Forwarded-For") + if ip == "" { + ip = r.RemoteAddr + } + data := map[string]any{} if err := json.Unmarshal(body, &data); err != nil { http.Error(w, err.Error(), http.StatusBadRequest)