mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-06 08:22:24 +01:00
feature (#585): support for proxied ip when logging intrusions
This commit is contained in:
parent
96b4ca786a
commit
36c006680c
1 changed files with 9 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue