Skip to content

Commit 5ddd6f3

Browse files
authored
Add lgtm.io excludes (#1101)
1 parent d020b17 commit 5ddd6f3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

common/http.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
436443
func (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 {

scripts/azvnet-integration/notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
dbutils.widgets.text("department", "")
99

1010
print(f'Department is {dbutils.widgets.get("department")}')
11-
print(f'But secret is redacted: {dbutils.secrets.get("terraform", "blob_storage_key")}')
11+
print(f'But secret is redacted: {dbutils.secrets.get("terraform", "blob_storage_key")}') # lgtm [py/clear-text-logging-sensitive-data]

0 commit comments

Comments
 (0)