Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-laterman committed Dec 6, 2024
1 parent bdfc5b3 commit ecdeb34
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 8 additions & 1 deletion internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,18 @@ func redactOutput(cfg *Config) Output {
}

for k := range redacted.Elasticsearch.Headers {
if strings.Contains(strings.ToLower(k), "auth") || strings.Contains(strings.ToLower(k), "token") || strings.Contains(strings.ToLower(k), "key") { // best-effort scan to redact sensitive headers
lk := strings.ToLower(k)
if strings.Contains(lk, "auth") || strings.Contains(lk, "token") || strings.Contains(lk, "key") || strings.Contains(lk, "bearer") { // best-effort scan to redact sensitive headers
redacted.Elasticsearch.Headers[k] = kRedacted
}
}

for k := range redacted.Elasticsearch.ProxyHeaders {
lk := strings.ToLower(k)
if strings.Contains(lk, "auth") || strings.Contains(lk, "token") || strings.Contains(lk, "key") || strings.Contains(lk, "bearer") { // best-effort scan to redact sensitive headers
redacted.Elasticsearch.ProxyHeaders[k] = kRedacted
}
}
return redacted
}

Expand Down
31 changes: 28 additions & 3 deletions internal/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,14 @@ func TestConfigRedact(t *testing.T) {
},
},
{
name: "Redact custom authorization output header",
name: "Redact custom output headers",
inputCfg: &Config{
Inputs: []Input{{}},
Output: Output{
Elasticsearch: Elasticsearch{
Protocol: "https",
Hosts: []string{"localhost:9200"},
Headers: map[string]string{"X-Authorization": "secretValue", "X-Custom": "value"},
Headers: map[string]string{"X-Authorization": "secretValue", "X-Custom": "value", "X-App-Token": "customToken", "X-App-Key": "secretKey", "X-Custom-Bearer": "secretBearer"},
ServiceTokenPath: "path/to/file",
},
},
Expand All @@ -445,7 +445,32 @@ func TestConfigRedact(t *testing.T) {
Elasticsearch: Elasticsearch{
Protocol: "https",
Hosts: []string{"localhost:9200"},
Headers: map[string]string{"X-Authorization": kRedacted, "X-Custom": "value"},
Headers: map[string]string{"X-Authorization": kRedacted, "X-Custom": "value", "X-App-Token": kRedacted, "X-App-Key": kRedacted, "X-Custom-Bearer": kRedacted},
ServiceTokenPath: "path/to/file",
},
},
},
},
{
name: "Redact proxy authorization output header",
inputCfg: &Config{
Inputs: []Input{{}},
Output: Output{
Elasticsearch: Elasticsearch{
Protocol: "https",
Hosts: []string{"localhost:9200"},
ProxyHeaders: map[string]string{"X-Proxy-Authorization": "secretValue"},
ServiceTokenPath: "path/to/file",
},
},
},
redactedCfg: &Config{
Inputs: []Input{{}},
Output: Output{
Elasticsearch: Elasticsearch{
Protocol: "https",
Hosts: []string{"localhost:9200"},
ProxyHeaders: map[string]string{"X-Proxy-Authorization": kRedacted},
ServiceTokenPath: "path/to/file",
},
},
Expand Down

0 comments on commit ecdeb34

Please sign in to comment.