Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide request info for sensitive urls #3175

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/app/backend/handler/apihandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,38 @@ func TestMapUrlToResource(t *testing.T) {
}

func TestFormatRequestLog(t *testing.T) {
req, err := http.NewRequest("PUT", "/api/v1/pod", bytes.NewReader([]byte("{}")))
if err != nil {
t.Error("Cannot mockup request")
}
cases := []struct {
request *restful.Request
method string
uri string
content *bytes.Reader
expected string
}{
{
&restful.Request{
Request: req,
},
"PUT",
"/api/v1/pod",
bytes.NewReader([]byte("{}")),
"Incoming HTTP/1.1 PUT /api/v1/pod request",
},
{
"POST",
"/api/v1/login",
bytes.NewReader([]byte("{}")),
"Incoming HTTP/1.1 POST /api/v1/login request from : { contents hidden }",
},
}

for _, c := range cases {
actual := formatRequestLog(c.request)
req, err := http.NewRequest(c.method, c.uri, c.content)
if err != nil {
t.Error("Cannot mockup request")
}

var restfulRequest restful.Request
restfulRequest.Request = req

actual := formatRequestLog(&restfulRequest)
if !strings.Contains(actual, c.expected) {
t.Errorf("formatRequestLog(%#v) returns %#v, expected to contain %#v", c.request, actual, c.expected)
t.Errorf("formatRequestLog(%#v) returns %#v, expected to contain %#v", req, actual, c.expected)
}
}
}
11 changes: 11 additions & 0 deletions src/app/backend/handler/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func formatRequestLog(request *restful.Request) string {
}

content := "{}"

entity := make(map[string]interface{})
request.ReadEntity(&entity)
if len(entity) > 0 {
Expand All @@ -76,6 +77,16 @@ func formatRequestLog(request *restful.Request) string {
}
}

// Great now let's filter out any content from sensitive URLs
var sensitive_urls [2]string
sensitive_urls[0] = "/api/v1/login"
sensitive_urls[1] = "/api/v1/csrftoken/login"
for _, a := range sensitive_urls {
if a == uri {
content = "{ contents hidden }"
}
}

return fmt.Sprintf(RequestLogString, time.Now().Format(time.RFC3339), request.Request.Proto,
request.Request.Method, uri, request.Request.RemoteAddr, content)
}
Expand Down