mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-20 18:26:29 +03:00
lib/httpserver: properly quote the returned address from GetQuotedRemoteAddr() for requests with X-Forwarded-For header
Make sure that the quoted address can be used as JSON string. Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4676#issuecomment-1663203424 This is a follow up for252643d100andac0b7e0421Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/4676
This commit is contained in:
@@ -436,11 +436,12 @@ var (
|
||||
|
||||
// GetQuotedRemoteAddr returns quoted remote address.
|
||||
func GetQuotedRemoteAddr(r *http.Request) string {
|
||||
remoteAddr := strconv.Quote(r.RemoteAddr) // quote remoteAddr and X-Forwarded-For, since they may contain untrusted input
|
||||
remoteAddr := r.RemoteAddr
|
||||
if addr := r.Header.Get("X-Forwarded-For"); addr != "" {
|
||||
remoteAddr += ", X-Forwarded-For: " + strconv.Quote(addr)
|
||||
remoteAddr += ", X-Forwarded-For: " + addr
|
||||
}
|
||||
return remoteAddr
|
||||
// quote remoteAddr and X-Forwarded-For, since they may contain untrusted input
|
||||
return strconv.Quote(remoteAddr)
|
||||
}
|
||||
|
||||
// Errorf writes formatted error message to w and to logger.
|
||||
|
||||
Reference in New Issue
Block a user