[MM-15639] Add config setting to explicitly define which IP headers are trusted (#10907)
* Add config setting to explicitly define which IP headers are trusted * fix variable shadowing * Optimize code flow; Add Ratelimit test for header set * Extend Ratelimit tests * Add additional unit tests * Structured logging
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e8af4872c6
Коммит
2d97f01781
@@ -63,7 +63,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
)
|
||||
c.App.T, _ = utils.GetTranslationsAndLocale(w, r)
|
||||
c.App.RequestId = model.NewId()
|
||||
c.App.IpAddress = utils.GetIpAddress(r)
|
||||
c.App.IpAddress = utils.GetIpAddress(r, c.App.Config().ServiceSettings.TrustedProxyIPHeader)
|
||||
c.App.UserAgent = r.UserAgent()
|
||||
c.App.AcceptLanguage = r.Header.Get("Accept-Language")
|
||||
c.Params = ParamsFromRequest(r)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
@@ -61,8 +60,8 @@ func CheckClientCompatability(agentString string) bool {
|
||||
|
||||
func Handle404(config configservice.ConfigService, w http.ResponseWriter, r *http.Request) {
|
||||
err := model.NewAppError("Handle404", "api.context.404.app_error", nil, "", http.StatusNotFound)
|
||||
|
||||
mlog.Debug(fmt.Sprintf("%v: code=404 ip=%v", r.URL.Path, utils.GetIpAddress(r)))
|
||||
ipAddress := utils.GetIpAddress(r, config.Config().ServiceSettings.TrustedProxyIPHeader)
|
||||
mlog.Debug("not found handler triggered", mlog.String("path", r.URL.Path), mlog.Int("code", 404), mlog.String("ip", ipAddress))
|
||||
|
||||
if IsApiCall(config, r) {
|
||||
w.WriteHeader(err.StatusCode)
|
||||
|
||||
Ссылка в новой задаче
Block a user