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

fix: redact password in logs if specified as part of URL #413

Merged
merged 2 commits into from
Jul 15, 2024
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
2 changes: 1 addition & 1 deletion internal/httpconfig/httpconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewHTTPConfig(proxyConfig config.ProxyConfig, authKey credential.SDKCredent
return ret, errProxyAuthWithoutProxyURL
}
if proxyConfig.URL.IsDefined() {
loggers.Infof("Using proxy server at %s", proxyConfig.URL)
loggers.Infof("Using proxy server at %s", proxyConfig.URL.Get().Redacted())
}

caCertFiles := proxyConfig.CACertFiles.Values()
Expand Down
20 changes: 20 additions & 0 deletions internal/httpconfig/httpconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/x509"
"net/http"
"net/http/httptest"
"net/url"
"os"
"testing"

Expand Down Expand Up @@ -137,3 +138,22 @@ func TestNTLMProxyInvalidConfigs(t *testing.T) {
}
})
}

func TestLogsRedactConnectionPassword(t *testing.T) {
// Username and password are specified separately in NTLM auth won't show in logs as they're not part of server name
url1, _ := configtypes.NewOptURLAbsoluteFromString("http://my-proxy")
proxyConfig1 := config.ProxyConfig{NTLMAuth: true, URL: url1, User: "my-user", Password: "my-pass"}
mockLog1 := ldlogtest.NewMockLog()
_, err := NewHTTPConfig(proxyConfig1, nil, "", mockLog1.Loggers)
assert.NoError(t, err)
mockLog1.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://my-proxy$")

// When username and password are configured as part of server name, verify the password is redacted
url2, _ := url.Parse("http://my-user:my-password@my-proxy")
url2Absolute, _ := configtypes.NewOptURLAbsolute(url2)
proxyConfig2 := config.ProxyConfig{URL: url2Absolute}
mockLog2 := ldlogtest.NewMockLog()
_, err = NewHTTPConfig(proxyConfig2, nil, "", mockLog2.Loggers)
assert.NoError(t, err)
mockLog2.AssertMessageMatch(t, true, ldlog.Info, "Using proxy server at http://my-user:xxxxx@my-proxy$")
}
Loading