Skip to content

Commit

Permalink
added masking key in log with special <hidden> value
Browse files Browse the repository at this point in the history
  • Loading branch information
dencoded committed Nov 22, 2017
1 parent 1264239 commit d0d1dc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion log_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ import (
"github.com/TykTechnologies/tyk/config"
)

// identifies that field value was hidden before output to the log
const (
logHiddenValue = "<hidden>"
)

func getLogEntryForRequest(r *http.Request, key string, data map[string]interface{}) *logrus.Entry {
// populate http request fields
fields := logrus.Fields{
"path": r.URL.Path,
"origin": requestIP(r),
}
// add key to log if configured to do so
if key != "" && config.Global.EnableKeyLogging {
if key != "" {
fields["key"] = key
if !config.Global.EnableKeyLogging {
fields["key"] = logHiddenValue
}
}
// add to log additional fields if any passed
if data != nil && len(data) > 0 {
Expand Down
2 changes: 2 additions & 0 deletions log_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func TestGetLogEntryForRequest(t *testing.T) {
Result: logrus.WithFields(logrus.Fields{
"path": "/test",
"origin": "127.0.0.1",
"key": logHiddenValue,
}),
},
// enable_key_logging is not set, key is not passed, no additional data field
Expand All @@ -94,6 +95,7 @@ func TestGetLogEntryForRequest(t *testing.T) {
"origin": "127.0.0.1",
"a": 1,
"b": "test",
"key": logHiddenValue,
}),
},
// enable_key_logging is not set, key is not passed, additional data fields are passed
Expand Down

0 comments on commit d0d1dc3

Please sign in to comment.