Skip to content

Go: go/log-injection produces false positives for logrus when sanitising formatters are used #11657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mbg opened this issue Dec 12, 2022 · 4 comments
Assignees

Comments

@mbg
Copy link
Member

mbg commented Dec 12, 2022

Description of the false positive

The go/log-injection (CWE-117) query identifies log entries that are created from user input without proper sanitisation. The logrus library is vulnerable to this when the default output formatter is used. However, different output formatters, such as JSONFormatter, may sanitise log entries themselves. The go/log-injection query is not currently aware of this behaviour and will report false positives whenever logrus is used for logging and log entries are based on unsanitised user data, even if a sanitising output formatter is used.

Code samples or links to source code

In the following example, go/log-injection will report that the log entry constructed using logrus.Fields depends on a user-provided value that has not been sanitised:

func example(req *http.Request, ctx *goproxy.ProxyCtx) {
	username := req.URL.Query()["username"][0]
	logrus.SetFormatter(&logrus.JSONFormatter{})
	logrus.WithFields(logrus.Fields{
		"USERNAME": username,
	})
}
@elgohr
Copy link

elgohr commented Feb 9, 2023

Hey, is #12132 an intermediate state or the final result?

@smowton
Copy link
Contributor

smowton commented Feb 9, 2023

Most likely permanent. We found that accurately diagnosing whether a JSON or other injection-resistant formatter would be in use was too error-prone; we'd either get many false positives or many false negatives whichever way we tried to characterise the situation. Other languages already specify log-injection is a medium-precision query for similar reasons, so we figured best to simply bring the Go query into line.

@elgohr
Copy link

elgohr commented Feb 9, 2023

Would be great to have a way for ignoring a set of CWEs within a scan (like paths-ignore), so people don't have to ignore every single finding for every log-line.

@smowton
Copy link
Contributor

smowton commented Feb 9, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants