This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Description
CWE-117: Improper Output Neutralization for Logs
CWE-117 is being reported by CodeQL in the following code:
func makeErrorForHTTPResponse(resp *http.Response) error {
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
url := resp.Request.URL.String()
safeURL := strings.Replace(url, "\n", "", -1)
safeURL = strings.Replace(safeURL, "\r", "", -1)
return fmt.Errorf("%s %s returned HTTP %s; \n\n %#q", resp.Request.Method, safeURL, resp.Status, bodyBytes)
}
Despite this code being near identical to the provided "good" example
func handlerGood(req *http.Request) {
username := req.URL.Query()["username"][0]
escapedUsername := strings.Replace(username, "\n", "", -1)
escapedUsername = strings.Replace(escapedUsername, "\r", "", -1)
log.Printf("user %s logged in.\n", escapedUsername)
}
here.
Here is a screen shot of the output logs for further clarification

It appears that CodeQL completely ignores the above two functions performing the string replacement.