Enhance logging of CSRF Warning (#11630)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
0fec6db7fc
Коммит
cb534c704e
@@ -119,10 +119,25 @@ func (a *App) servePluginRequest(w http.ResponseWriter, r *http.Request, handler
|
|||||||
// ToDo(DSchalla) 2019/01/04: Remove after deprecation period and only allow CSRF Header (MM-13657)
|
// ToDo(DSchalla) 2019/01/04: Remove after deprecation period and only allow CSRF Header (MM-13657)
|
||||||
if r.Header.Get(model.HEADER_REQUESTED_WITH) == model.HEADER_REQUESTED_WITH_XML && !csrfCheckPassed {
|
if r.Header.Get(model.HEADER_REQUESTED_WITH) == model.HEADER_REQUESTED_WITH_XML && !csrfCheckPassed {
|
||||||
csrfErrorMessage := "CSRF Check failed for request - Please migrate your plugin to either send a CSRF Header or Form Field, XMLHttpRequest is deprecated"
|
csrfErrorMessage := "CSRF Check failed for request - Please migrate your plugin to either send a CSRF Header or Form Field, XMLHttpRequest is deprecated"
|
||||||
|
sid := ""
|
||||||
|
userId := ""
|
||||||
|
|
||||||
|
if session != nil {
|
||||||
|
sid = session.Id
|
||||||
|
userId = session.UserId
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := []mlog.Field{
|
||||||
|
mlog.String("path", r.URL.Path),
|
||||||
|
mlog.String("ip", r.RemoteAddr),
|
||||||
|
mlog.String("session_id", sid),
|
||||||
|
mlog.String("user_id", userId),
|
||||||
|
}
|
||||||
|
|
||||||
if *a.Config().ServiceSettings.ExperimentalStrictCSRFEnforcement {
|
if *a.Config().ServiceSettings.ExperimentalStrictCSRFEnforcement {
|
||||||
a.Log.Warn(csrfErrorMessage)
|
a.Log.Warn(csrfErrorMessage, fields...)
|
||||||
} else {
|
} else {
|
||||||
a.Log.Debug(csrfErrorMessage)
|
a.Log.Debug(csrfErrorMessage, fields...)
|
||||||
csrfCheckPassed = true
|
csrfCheckPassed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,10 +208,26 @@ func (h *Handler) checkCSRFToken(c *Context, r *http.Request, token string, toke
|
|||||||
} else if r.Header.Get(model.HEADER_REQUESTED_WITH) == model.HEADER_REQUESTED_WITH_XML {
|
} else if r.Header.Get(model.HEADER_REQUESTED_WITH) == model.HEADER_REQUESTED_WITH_XML {
|
||||||
// ToDo(DSchalla) 2019/01/04: Remove after deprecation period and only allow CSRF Header (MM-13657)
|
// ToDo(DSchalla) 2019/01/04: Remove after deprecation period and only allow CSRF Header (MM-13657)
|
||||||
csrfErrorMessage := "CSRF Header check failed for request - Please upgrade your web application or custom app to set a CSRF Header"
|
csrfErrorMessage := "CSRF Header check failed for request - Please upgrade your web application or custom app to set a CSRF Header"
|
||||||
|
|
||||||
|
sid := ""
|
||||||
|
userId := ""
|
||||||
|
|
||||||
|
if session != nil {
|
||||||
|
sid = session.Id
|
||||||
|
userId = session.UserId
|
||||||
|
}
|
||||||
|
|
||||||
|
fields := []mlog.Field{
|
||||||
|
mlog.String("path", r.URL.Path),
|
||||||
|
mlog.String("ip", r.RemoteAddr),
|
||||||
|
mlog.String("session_id", sid),
|
||||||
|
mlog.String("user_id", userId),
|
||||||
|
}
|
||||||
|
|
||||||
if *c.App.Config().ServiceSettings.ExperimentalStrictCSRFEnforcement {
|
if *c.App.Config().ServiceSettings.ExperimentalStrictCSRFEnforcement {
|
||||||
c.Log.Warn(csrfErrorMessage)
|
c.Log.Warn(csrfErrorMessage, fields...)
|
||||||
} else {
|
} else {
|
||||||
c.Log.Debug(csrfErrorMessage)
|
c.Log.Debug(csrfErrorMessage, fields...)
|
||||||
csrfCheckPassed = true
|
csrfCheckPassed = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user