github / github/codeql

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

Đang mở
#11,657 4 bình luận 1 reaction 1 người được giao Được @mbg nhận Xem trên GitHub
false-positive Go
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the false positive**

The `go/log-injection` ([CWE-117](https://cwe.mitre.org/data/definitions/117.html)) 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:

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.