feature (#585): support for proxied ip when logging intrusions

This commit is contained in:
Juan Carlos Ramirez
2023-04-07 00:19:16 -05:00
committed by GitHub
parent 96b4ca786a
commit 36c006680c

View File

@ -100,7 +100,7 @@ func SecureOrigin(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *A
return
}
Log.Warning("Intrusion detection: %s - %s", req.RemoteAddr, req.URL.String())
Log.Warning("Intrusion detection: %s - %s", RetrievePublicIp(req), req.URL.String())
SendErrorResult(res, ErrNotAllowed)
}
}
@ -182,3 +182,11 @@ func EnableCors(req *http.Request, res http.ResponseWriter, host string) error {
h.Set("Access-Control-Allow-Headers", "Authorization")
return nil
}
func RetrievePublicIp(req *http.Request) string {
if req.Header.Get("X-Forwarded-For") != "" {
return req.Header.Get("X-Forwarded-For")
} else {
return req.RemoteAddr
}
}