mirror of https://github.com/status-im/consul.git
agent: sanitize ui metrics proxy header values on agent/self endpoint (#9104)
This commit is contained in:
parent
a33c50ef0d
commit
8e616a93c1
|
@ -1843,6 +1843,21 @@ func sanitize(name string, v reflect.Value) reflect.Value {
|
||||||
|
|
||||||
case isArray(typ) || isSlice(typ):
|
case isArray(typ) || isSlice(typ):
|
||||||
ma := make([]interface{}, 0, v.Len())
|
ma := make([]interface{}, 0, v.Len())
|
||||||
|
|
||||||
|
if name == "AddHeaders" {
|
||||||
|
// must be UIConfig.MetricsProxy.AddHeaders
|
||||||
|
for i := 0; i < v.Len(); i++ {
|
||||||
|
addr := v.Index(i).Addr()
|
||||||
|
hdr := addr.Interface().(*UIMetricsProxyAddHeader)
|
||||||
|
hm := map[string]interface{}{
|
||||||
|
"Name": hdr.Name,
|
||||||
|
"Value": "hidden",
|
||||||
|
}
|
||||||
|
ma = append(ma, hm)
|
||||||
|
}
|
||||||
|
return reflect.ValueOf(ma)
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(name, "SerfAllowedCIDRs") {
|
if strings.HasPrefix(name, "SerfAllowedCIDRs") {
|
||||||
for i := 0; i < v.Len(); i++ {
|
for i := 0; i < v.Len(); i++ {
|
||||||
addr := v.Index(i).Addr()
|
addr := v.Index(i).Addr()
|
||||||
|
|
|
@ -7470,6 +7470,13 @@ func TestSanitize(t *testing.T) {
|
||||||
*parseCIDR(t, "127.0.0.0/8"),
|
*parseCIDR(t, "127.0.0.0/8"),
|
||||||
},
|
},
|
||||||
TxnMaxReqLen: 5678000000000000,
|
TxnMaxReqLen: 5678000000000000,
|
||||||
|
UIConfig: UIConfig{
|
||||||
|
MetricsProxy: UIMetricsProxy{
|
||||||
|
AddHeaders: []UIMetricsProxyAddHeader{
|
||||||
|
{Name: "foo", Value: "secret"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rtJSON := `{
|
rtJSON := `{
|
||||||
|
@ -7812,7 +7819,12 @@ func TestSanitize(t *testing.T) {
|
||||||
"MetricsProviderFiles": [],
|
"MetricsProviderFiles": [],
|
||||||
"MetricsProviderOptionsJSON": "",
|
"MetricsProviderOptionsJSON": "",
|
||||||
"MetricsProxy": {
|
"MetricsProxy": {
|
||||||
"AddHeaders": [],
|
"AddHeaders": [
|
||||||
|
{
|
||||||
|
"Name": "foo",
|
||||||
|
"Value": "hidden"
|
||||||
|
}
|
||||||
|
],
|
||||||
"BaseURL": "",
|
"BaseURL": "",
|
||||||
"PathAllowlist": []
|
"PathAllowlist": []
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue