MM-53165 Add X-Forwarded-For header to audit for rest api calls (#24390)

* Add X-Forwarded-For header to audit for rest api calls

* fix unit test
Этот коммит содержится в:
Doug Lauder
2023-08-28 07:24:55 -04:00
коммит произвёл GitHub
родитель 0a499770e6
Коммит 84b52333c1
6 изменённых файлов: 28 добавлений и 15 удалений

Просмотреть файл

@@ -59,10 +59,11 @@ func (c *Context) MakeAuditRecord(event string, initialStatus string) *audit.Rec
EventName: event,
Status: initialStatus,
Actor: audit.EventActor{
UserId: c.AppContext.Session().UserId,
SessionId: c.AppContext.Session().Id,
Client: c.AppContext.UserAgent(),
IpAddress: c.AppContext.IPAddress(),
UserId: c.AppContext.Session().UserId,
SessionId: c.AppContext.Session().Id,
Client: c.AppContext.UserAgent(),
IpAddress: c.AppContext.IPAddress(),
XForwardedFor: c.AppContext.XForwardedFor(),
},
Meta: map[string]interface{}{
audit.KeyAPIPath: c.AppContext.Path(),

Просмотреть файл

@@ -14,11 +14,12 @@ import (
"strings"
"time"
"github.com/mattermost/gziphandler"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
spanlog "github.com/opentracing/opentracing-go/log"
"github.com/mattermost/gziphandler"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/public/shared/i18n"
"github.com/mattermost/mattermost/server/public/shared/mlog"
@@ -172,6 +173,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
c.AppContext.SetT(t)
c.AppContext.SetRequestId(requestID)
c.AppContext.SetIPAddress(utils.GetIPAddress(r, c.App.Config().ServiceSettings.TrustedProxyIPHeader))
c.AppContext.SetXForwardedFor(r.Header.Get("X-Forwarded-For"))
c.AppContext.SetUserAgent(r.UserAgent())
c.AppContext.SetAcceptLanguage(r.Header.Get("Accept-Language"))
c.AppContext.SetPath(r.URL.Path)