github / github/codeql

False positive - Log entries created from user input

未關閉
#10,922 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
Go question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

**Description of the issue**

in-place sanitization code is not recognized and constantly reports false positives with "Log entries created from user input"

For example, when using the following sanitization, logging sanitized user input produces a false positive.
```
// contain at most 60 characters
// contain only lowercase alphanumeric characters or '-'
// start with an alphanumeric character
// end with an alphanumeric character
func Sanitize(in string) string {
if len(in) > 60 {
return ""
}
var alphanumeric bool
for i, r := range in {
if (97 <= r && r <= 122) || (48 <= r && r <= 57) {
alphanumeric = true
continue
}
if r == 45 {
alphanumeric = false
// first letter
if i == 0 {
return ""
}
continue
}
return ""
}
// last letter
if !alphanumeric {
return ""
}
return in
}
```

is there a workaround or a way to signal to CodeQL that this is in-place sanitization and no alert is needed?
That is, without moving to a less efficient non-in-place sanitization...

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。