@@ -153,7 +153,9 @@ func accessURL(req *http.Request) string {
153153 u := * req .URL
154154 u .RawQuery = ""
155155 u .Fragment = ""
156- return u .String ()
156+ // Redacted() masks any password embedded in the URL userinfo so credentials
157+ // are never written to logs in clear text.
158+ return u .Redacted ()
157159}
158160
159161func hasDetailedTrace (config TraceConfig ) bool {
@@ -246,8 +248,10 @@ func jsonLogger(config TraceConfig, verbose logger.Verbose, rt http.RoundTripper
246248
247249 if err != nil {
248250 // Transport errors surface at INFO so a failed request is visible at -v=0.
249- kv = append (kv , "error" , err .Error ())
250- jsonLogAt (verbose , req , 0 , kv , "%s %s error %s" , req .Method , req .URL , elapsed .Truncate (time .Millisecond ))
251+ // StripSecrets/Redacted keep any credentials embedded in the URL (e.g. a
252+ // url.Error wrapping "https://user:pass@host") out of the logs.
253+ kv = append (kv , "error" , logger .StripSecrets (err .Error ()))
254+ jsonLogAt (verbose , req , 0 , kv , "%s %s error %s" , req .Method , req .URL .Redacted (), elapsed .Truncate (time .Millisecond ))
251255 return nil , err
252256 }
253257
@@ -272,15 +276,15 @@ func jsonLogger(config TraceConfig, verbose logger.Verbose, rt http.RoundTripper
272276 kv = append (kv , "responseBody" , sanitizeBody (body ))
273277 }
274278 }
275- jsonLogAt (verbose , req , 0 , kv , "%s %s %d %s" , req .Method , req .URL , resp .StatusCode , elapsed .Truncate (time .Millisecond ))
279+ jsonLogAt (verbose , req , 0 , kv , "%s %s %d %s" , req .Method , req .URL . Redacted () , resp .StatusCode , elapsed .Truncate (time .Millisecond ))
276280 return resp , nil
277281 }
278282
279283 // Error-only mode suppresses the success line (see logPrettyAccess).
280284 if config .AccessLogErrorsOnly {
281285 return resp , nil
282286 }
283- jsonLogAt (verbose , req , level , kv , "%s %s %d %s" , req .Method , req .URL , resp .StatusCode , elapsed .Truncate (time .Millisecond ))
287+ jsonLogAt (verbose , req , level , kv , "%s %s %d %s" , req .Method , req .URL . Redacted () , resp .StatusCode , elapsed .Truncate (time .Millisecond ))
284288 return resp , nil
285289}
286290
@@ -368,7 +372,7 @@ func logPrettyAccess(config TraceConfig, verbose logger.Verbose, req *http.Reque
368372 // error-only mode at -v=0; the body captures the cause (e.g. an HTML 404/500
369373 // page) without raising verbosity.
370374 if err != nil {
371- logAt (verbose , req , 0 , "%s %s %s %s" , method , url , console .Redf ("error: %s" , err .Error ()), dur )
375+ logAt (verbose , req , 0 , "%s %s %s %s" , method , url , console .Redf ("error: %s" , logger . StripSecrets ( err .Error () )), dur )
372376 return
373377 }
374378 statusCode := 0
0 commit comments