mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-30 01:26:43 +08:00
feature (#585): support for proxied ip when logging intrusions
This commit is contained in:
committed by
GitHub
parent
96b4ca786a
commit
36c006680c
@ -100,7 +100,7 @@ func SecureOrigin(fn func(*App, http.ResponseWriter, *http.Request)) func(ctx *A
|
|||||||
return
|
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)
|
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")
|
h.Set("Access-Control-Allow-Headers", "Authorization")
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user