forked from TrueCloudLab/certificates
Sanitize log entries in logging package
This commit is contained in:
parent
b62f4d1000
commit
90d2785776
1 changed files with 9 additions and 3 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -78,7 +79,7 @@ func (l *LoggerHandler) writeEntry(w ResponseLogger, r *http.Request, t time.Tim
|
||||||
uri = r.Host
|
uri = r.Host
|
||||||
}
|
}
|
||||||
if uri == "" {
|
if uri == "" {
|
||||||
uri = r.URL.RequestURI()
|
uri = sanitizeLogEntry(r.URL.RequestURI())
|
||||||
}
|
}
|
||||||
|
|
||||||
status := w.StatusCode()
|
status := w.StatusCode()
|
||||||
|
@ -96,8 +97,8 @@ func (l *LoggerHandler) writeEntry(w ResponseLogger, r *http.Request, t time.Tim
|
||||||
"protocol": r.Proto,
|
"protocol": r.Proto,
|
||||||
"status": status,
|
"status": status,
|
||||||
"size": w.Size(),
|
"size": w.Size(),
|
||||||
"referer": r.Referer(),
|
"referer": sanitizeLogEntry(r.Referer()),
|
||||||
"user-agent": r.UserAgent(),
|
"user-agent": sanitizeLogEntry(r.UserAgent()),
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range w.Fields() {
|
for k, v := range w.Fields() {
|
||||||
|
@ -117,3 +118,8 @@ func (l *LoggerHandler) writeEntry(w ResponseLogger, r *http.Request, t time.Tim
|
||||||
l.logger.WithFields(fields).Error()
|
l.logger.WithFields(fields).Error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeLogEntry(s string) string {
|
||||||
|
escaped := strings.Replace(s, "\n", "", -1)
|
||||||
|
return strings.Replace(escaped, "\r", "", -1)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue