Skip to content

Commit

Permalink
Sanitize response body before logging (kolide#2020)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Jan 2, 2025
1 parent 06e3e07 commit 97f4ab0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/log/logshipper/authedhttpsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"time"
)

Expand Down Expand Up @@ -41,7 +42,8 @@ func (a *authedHttpSender) Send(r io.Reader) error {
return fmt.Errorf("received non 200 http status code: %d, error reading body response body %w", resp.StatusCode, err)
}

return fmt.Errorf("received non 200 http status code: %d, response body: %s", resp.StatusCode, bodyData)
escapedBodyData := strings.ReplaceAll(strings.ReplaceAll(string(bodyData), "\n", ""), "\r", "") // remove any newlines
return fmt.Errorf("received non 200 http status code: %d, response body: %s", resp.StatusCode, escapedBodyData)
}
return nil
}

0 comments on commit 97f4ab0

Please sign in to comment.