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

CWE-117 False positive #635

@theAntiYeti

Description

@theAntiYeti

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
Screenshot from 2021-12-13 18-14-19

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions