github / github/codeql

False positive in Go / Golang context when logging using %T

Đang mở
#18,926 1 bình luận 0 reaction 0 người được giao 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 warning](https://github.com/developerproductivity/costpuller/security/code-scanning/2) is "Clear-text logging of sensitive information", but what is actually logged is the _type_ of the variable which holds the information and not the information itself.

CodeQL correctly determines that a variable potentially holding a piece of sensitive information is [referenced in a `log.Fatalf()` call](https://github.com/developerproductivity/costpuller/blob/517634a461440261d5f0e5a3ccab0326e32c69a0/cloudability.go#L214-L214), but it misses the fact that the reference is processed using a `%T` format specifier which will result in the log receiving the _type_ of the data and not the _value_ of the data:

```go
apiKeyPair, ok := apiKeyPairAny.([]any)
if !ok {
log.Fatalf("Error reading Cloudability API keypair, expected an array, found %T",
apiKeyPairAny)
```

**Possible workaround**

I'm hoping that the following will suffice to work around the problem, but it's ugly and really shouldn't be necessary!

```go
log.Fatalf("Error reading Cloudability API keypair, expected an array, found %v",
reflect.TypeOf(apiKeyPairAny).String())
```

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

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

Hướng nghiên cứu

Start by reproducing the CodeQL alert in cloudability.go around line 214 and inspect how the log.Fatalf call and its %T format argument are interpreted. Confirm that logging a value with %T is not treated as clear-text logging of the value, while logging the value itself remains covered; done means the reported false positive is no longer raised.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go
Lĩnh vực
security
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

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.