Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(sdk-go): keep a base URL password out of the request log
Yudhi Armyndharis91b6fdfe75e9
diff --git a/sdk/go/client_test.go b/sdk/go/client_test.goindex 0e3f4d630..2ae3f715d 100644--- a/sdk/go/client_test.go+++ b/sdk/go/client_test.go@@ -5,6 +5,7 @@ import ("context""encoding/json""errors"+ "fmt""io""net/http""net/http/httptest"@@ -1695,3 +1696,28 @@ func TestTimeoutReportsTheBudgetThatExpired(t *testing.T) {}}}++// argsLogger records every logged key-value argument as text.+type argsLogger struct{ text strings.Builder }++func (l *argsLogger) Log(_ context.Context, _ string, msg string, args ...any) {+ fmt.Fprintln(&l.text, msg, args)+}++// A base URL may carry basic-auth credentials for a fronting proxy; the+// password must not reach the request log.+func TestRequestLogRedactsBaseURLPassword(t *testing.T) {+ ok := &recordTransport{status: 200, body: `{}`}+ failing := RoundTripperFunc(func(*http.Request) (*http.Response, error) { return nil, errors.New("refused") })+ for _, rt := range []http.RoundTripper{ok, failing} {+ lg := &argsLogger{}+ c, err := New("https://proxyuser:[email protected]", "k", WithTransport(rt), WithLogger(lg))+ if err != nil {+ t.Fatalf("New: %v", err)+ }+ _, _ = c.Health.Check(context.Background())+ if got := lg.text.String(); !strings.Contains(got, "api.example.com") || strings.Contains(got, "s3cret") {+ t.Errorf("request log = %q, want the URL without the password", got)+ }+ }+}diff --git a/sdk/go/transport.go b/sdk/go/transport.goindex 3588d7444..7532c826f 100644--- a/sdk/go/transport.go+++ b/sdk/go/transport.go@@ -83,12 +83,12 @@ func loggingMiddleware(log Logger) Middleware {dur := time.Since(start)if err != nil {log.Log(req.Context(), LevelError, "openwa request failed",- "method", req.Method, "url", req.URL.String(),+ "method", req.Method, "url", req.URL.Redacted(),"duration_ms", dur.Milliseconds(), "error", err.Error())return resp, err}log.Log(req.Context(), LevelDebug, "openwa request",- "method", req.Method, "url", req.URL.String(),+ "method", req.Method, "url", req.URL.Redacted(),"status", resp.StatusCode, "duration_ms", dur.Milliseconds())return resp, nil})