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

Stripping the Authorization Header from the Logs #2131

Merged
merged 1 commit into from
Oct 22, 2018
Merged
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
12 changes: 12 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ func (c *ArmClient) configureClient(client *autorest.Client, auth autorest.Autho
func withRequestLogging() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
// strip the authorization header prior to printing
authHeaderName := "Authorization"
auth := r.Header.Get(authHeaderName)
if auth != "" {
r.Header.Del(authHeaderName)
}

// dump request to wire format
if dump, err := httputil.DumpRequestOut(r, true); err == nil {
log.Printf("[DEBUG] AzureRM Request: \n%s\n", dump)
Expand All @@ -339,6 +346,11 @@ func withRequestLogging() autorest.SendDecorator {
log.Printf("[DEBUG] AzureRM Request: %s to %s\n", r.Method, r.URL)
}

// add the auth header back
if auth != "" {
r.Header.Add(authHeaderName, auth)
}

resp, err := s.Do(r)
if resp != nil {
// dump response to wire format
Expand Down