Skip to content

Commit 84dcbd1

Browse files
vigneshshanmugammergify-bot
authored andcommitted
[Heartbeat] redact authorization headers from logger (#26892)
* [Heartbeat] redact authorization headers from logger * add proxy-auth headers to the list (cherry picked from commit 3598bd8)
1 parent 012fc60 commit 84dcbd1

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

libbeat/common/config_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ func TestConfigPrintDebug(t *testing.T) {
7575
}
7676
]
7777
}
78+
`,
79+
},
80+
{
81+
"config selector redacts authorization headers",
82+
"config",
83+
map[string]interface{}{
84+
"config": map[string]interface{}{
85+
"headers": map[string]interface{}{
86+
"Authorization": "secret1",
87+
"authorization": "secret2",
88+
},
89+
},
90+
},
91+
`test:
92+
{
93+
"config": {
94+
"headers": {
95+
"Authorization": "xxxxx",
96+
"authorization": "xxxxx"
97+
}
98+
}
99+
}
78100
`,
79101
},
80102
{

libbeat/common/logging.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package common
1919

20+
import "strings"
21+
2022
var maskList = MakeStringSet(
2123
"password",
2224
"passphrase",
@@ -27,13 +29,15 @@ var maskList = MakeStringSet(
2729
"urls",
2830
"host",
2931
"hosts",
32+
"authorization",
33+
"proxy-authorization",
3034
)
3135

3236
func applyLoggingMask(c interface{}) {
3337
switch cfg := c.(type) {
3438
case map[string]interface{}:
3539
for k, v := range cfg {
36-
if maskList.Has(k) {
40+
if maskList.Has(strings.ToLower(k)) {
3741
if arr, ok := v.([]interface{}); ok {
3842
for i := range arr {
3943
arr[i] = "xxxxx"

0 commit comments

Comments
 (0)