@@ -433,14 +433,22 @@ func (c *DatabricksClient) userAgent(ctx context.Context) string {
433433 Version (), resource , terraformVersion )
434434}
435435
436+ // CWE-117 prevention
437+ func escapeNewLines (in string ) string {
438+ in = strings .Replace (in , "\n " , "" , - 1 )
439+ in = strings .Replace (in , "\r " , "" , - 1 )
440+ return in
441+ }
442+
436443func (c * DatabricksClient ) createDebugHeaders (header http.Header , host string ) string {
437444 headers := ""
438445 if c .DebugHeaders {
439446 if host != "" {
440- headers += fmt .Sprintf ("\n * Host: %s" , host )
447+ headers += fmt .Sprintf ("\n * Host: %s" , escapeNewLines ( host ) )
441448 }
442449 for k , v := range header {
443- headers += fmt .Sprintf ("\n * %s: %s" , k , onlyNBytes (strings .Join (v , "" ), c .DebugTruncateBytes ))
450+ trunc := onlyNBytes (strings .Join (v , "" ), c .DebugTruncateBytes )
451+ headers += fmt .Sprintf ("\n * %s: %s" , k , escapeNewLines (trunc ))
444452 }
445453 if len (headers ) > 0 {
446454 headers += "\n "
@@ -474,7 +482,8 @@ func (c *DatabricksClient) genericQuery(ctx context.Context, method, requestURL
474482 }
475483 }
476484 headers := c .createDebugHeaders (request .Header , c .Host )
477- log .Printf ("[DEBUG] %s %s %s%v" , method , request .URL .Path , headers , c .redactedDump (requestBody )) // lgtm[go/clear-text-logging]
485+ log .Printf ("[DEBUG] %s %s %s%v" , method , escapeNewLines (request .URL .Path ),
486+ headers , c .redactedDump (requestBody )) // lgtm [go/log-injection]
478487
479488 r , err := retryablehttp .FromRequest (request )
480489 if err != nil {
0 commit comments