github / github/codeql

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

オープン
#11,657 コメント 4 件 リアクション 1 件 担当者 1 名 @mbg が担当を希望しています GitHub で見る
false-positive Go
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

**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,
})
}
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。