Sanitize connect token in logging
This commit is contained in:
parent
f19f165afc
commit
e7ac416440
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -11,7 +12,11 @@ import (
|
|||||||
|
|
||||||
const loggerMessage = "http_request"
|
const loggerMessage = "http_request"
|
||||||
|
|
||||||
var logger *logrus.Logger
|
var (
|
||||||
|
logger *logrus.Logger
|
||||||
|
|
||||||
|
reConnectToken = regexp.MustCompile("/connect/(.*)")
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
@ -34,9 +39,13 @@ func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
|
|||||||
// Process request
|
// Process request
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|
||||||
// Skip logging static assets
|
if !debug {
|
||||||
if strings.Contains(path, "/static/") && !debug {
|
// Skip static assets logging
|
||||||
return
|
if strings.Contains(path, "/static/") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
path = sanitizeLogPath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
status := c.Writer.Status()
|
status := c.Writer.Status()
|
||||||
@ -72,3 +81,7 @@ func RequestLogger(logger *logrus.Logger) gin.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeLogPath(str string) string {
|
||||||
|
return reConnectToken.ReplaceAllString(str, "/connect/REDACTED")
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user