Skip to content

Commit f8a0f26

Browse files
thaJeztahTibor Vass
authored andcommitted
DebugRequestMiddleware: Remove path handling
Path-specific rules were removed, so this is no longer used. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 530e63c1a61b105a6f7fc143c5acb9b5cd87f958) Signed-off-by: Tibor Vass <[email protected]>
1 parent 73db8c7 commit f8a0f26

2 files changed

Lines changed: 8 additions & 50 deletions

File tree

api/server/middleware/debug.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWri
4141

4242
var postForm map[string]interface{}
4343
if err := json.Unmarshal(b, &postForm); err == nil {
44-
maskSecretKeys(postForm, r.RequestURI)
44+
maskSecretKeys(postForm)
4545
formStr, errMarshal := json.Marshal(postForm)
4646
if errMarshal == nil {
4747
logrus.Debugf("form data: %s", string(formStr))
@@ -54,18 +54,10 @@ func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWri
5454
}
5555
}
5656

57-
func maskSecretKeys(inp interface{}, path string) {
58-
// Remove any query string from the path
59-
idx := strings.Index(path, "?")
60-
if idx != -1 {
61-
path = path[:idx]
62-
}
63-
// Remove trailing / characters
64-
path = strings.TrimRight(path, "/")
65-
57+
func maskSecretKeys(inp interface{}) {
6658
if arr, ok := inp.([]interface{}); ok {
6759
for _, f := range arr {
68-
maskSecretKeys(f, path)
60+
maskSecretKeys(f)
6961
}
7062
return
7163
}
@@ -92,7 +84,7 @@ func maskSecretKeys(inp interface{}, path string) {
9284
continue loop0
9385
}
9486
}
95-
maskSecretKeys(v, path)
87+
maskSecretKeys(v)
9688
}
9789
}
9890
}

api/server/middleware/debug_test.go

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,16 @@ import (
1010
func TestMaskSecretKeys(t *testing.T) {
1111
tests := []struct {
1212
doc string
13-
path string
1413
input map[string]interface{}
1514
expected map[string]interface{}
1615
}{
1716
{
18-
doc: "secret create with API version",
19-
path: "/v1.30/secrets/create",
17+
doc: "secret/config create and update requests",
2018
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
2119
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
2220
},
2321
{
24-
doc: "secret create with API version and trailing slashes",
25-
path: "/v1.30/secrets/create//",
26-
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
27-
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
28-
},
29-
{
30-
doc: "secret create with query param",
31-
path: "/secrets/create?key=val",
32-
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
33-
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
34-
},
35-
{
36-
doc: "secret update with API version",
37-
path: "/v1.30/secrets/mysecret/update",
38-
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
39-
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
40-
},
41-
{
42-
doc: "secret update with API version and trailing slashes",
43-
path: "/v1.30/secrets/mysecret/update//",
44-
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
45-
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
46-
},
47-
{
48-
doc: "secret update with query parameter",
49-
path: "/secrets/mysecret/update?version=34",
50-
input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}},
51-
expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}},
52-
},
53-
{
54-
doc: "other paths with API version",
55-
path: "/v1.30/some/other/path",
22+
doc: "masking other fields (recursively)",
5623
input: map[string]interface{}{
5724
"password": "pass",
5825
"secret": "secret",
@@ -83,8 +50,7 @@ func TestMaskSecretKeys(t *testing.T) {
8350
},
8451
},
8552
{
86-
doc: "other paths with API version case insensitive",
87-
path: "/v1.30/some/other/path",
53+
doc: "case insensitive field matching",
8854
input: map[string]interface{}{
8955
"PASSWORD": "pass",
9056
"other": map[string]interface{}{
@@ -102,7 +68,7 @@ func TestMaskSecretKeys(t *testing.T) {
10268

10369
for _, testcase := range tests {
10470
t.Run(testcase.doc, func(t *testing.T) {
105-
maskSecretKeys(testcase.input, testcase.path)
71+
maskSecretKeys(testcase.input)
10672
assert.Check(t, is.DeepEqual(testcase.expected, testcase.input))
10773
})
10874
}

0 commit comments

Comments
 (0)