Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"encoding/json"
"net/http"
"net/http/httputil"
"strconv"

"code.cloudfoundry.org/lager/v3"
Expand Down Expand Up @@ -61,14 +60,6 @@ func handleUpdate(
return
}

dumpBody := true
b, err := httputil.DumpRequest(req, dumpBody)
if err != nil {
http.Error(w, "Failed to dump http body", http.StatusInternalServerError)
return
}

logger.Debug("API /cluster req", lager.Data{"dump": string(b)})
logger.Debug("API /cluster req form", lager.Data{"form": req.Form})

enabledStr := req.Form.Get("trafficEnabled")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api_test

import (
"encoding/base64"
"encoding/json"
"net/http"
"time"
Expand Down Expand Up @@ -217,6 +218,31 @@ var _ = Describe("ClusterEndpoint", func() {
})
})

Context("when a PATCH request includes an Authorization header", func() {
It("does not log the Authorization header credentials", func() {
const password = "supersecretpassword"
encodedCreds := base64.StdEncoding.EncodeToString(
[]byte("admin:" + password),
)

req, err := http.NewRequest(
"PATCH",
server.URL()+"?trafficEnabled=true",
nil,
)
Expect(err).NotTo(HaveOccurred())
req.SetBasicAuth("admin", password)

client := &http.Client{}
_, err = client.Do(req)
Expect(err).NotTo(HaveOccurred())

logContents := testLogger.Buffer().Contents()
Expect(logContents).ToNot(ContainSubstring(encodedCreds),
"Authorization header base64 value must not appear in logs")
})
})

Describe("POST", func() {
It("returns http 405 - Method not allowed", func() {
req, err := http.NewRequest("POST", server.URL(), nil)
Expand Down
Loading