Skip to content

Commit

Permalink
[Heartbeat] redact authorization headers from logger (#26892)
Browse files Browse the repository at this point in the history
* [Heartbeat] redact authorization headers from logger

* add proxy-auth headers to the list

(cherry picked from commit 3598bd8)
  • Loading branch information
vigneshshanmugam authored and mergify-bot committed Jul 16, 2021
1 parent 012fc60 commit 84dcbd1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions libbeat/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ func TestConfigPrintDebug(t *testing.T) {
}
]
}
`,
},
{
"config selector redacts authorization headers",
"config",
map[string]interface{}{
"config": map[string]interface{}{
"headers": map[string]interface{}{
"Authorization": "secret1",
"authorization": "secret2",
},
},
},
`test:
{
"config": {
"headers": {
"Authorization": "xxxxx",
"authorization": "xxxxx"
}
}
}
`,
},
{
Expand Down
6 changes: 5 additions & 1 deletion libbeat/common/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package common

import "strings"

var maskList = MakeStringSet(
"password",
"passphrase",
Expand All @@ -27,13 +29,15 @@ var maskList = MakeStringSet(
"urls",
"host",
"hosts",
"authorization",
"proxy-authorization",
)

func applyLoggingMask(c interface{}) {
switch cfg := c.(type) {
case map[string]interface{}:
for k, v := range cfg {
if maskList.Has(k) {
if maskList.Has(strings.ToLower(k)) {
if arr, ok := v.([]interface{}); ok {
for i := range arr {
arr[i] = "xxxxx"
Expand Down

0 comments on commit 84dcbd1

Please sign in to comment.