github / github/codeql

False positive - Log injection is not mitigated via replace with Regex argument in Kotlin

オープン
#17,423 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
false-positive Kotlin
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

**Description of the false positive**

CodeQL is reporting a log injection vulnerability even though I am deleting the problematic characters with Kotlin's `replace` function call with a Regex as its first parameter.

Reading the query (https://github.com/github/codeql/blob/main/java/ql/lib/semmle/code/java/security/LogInjection.qll) I suspect that's because it searches for uses of `replace` with either Strings or Chars as arguments (in order to check for line break removal), but not uses of `replace` with Regex as its first argument (in Kotlin, there is no `replaceAll` function, there is only a `replace` that can accept either String, Char or Regex).

I have also looked at the tests (https://github.com/github/codeql/blob/main/java/ql/test/query-tests/security/CWE-117/LogInjectionTest.java) and that's why I belive this might be the reason, as the tests always use `replaceAll` when working with regular expressions (as it is a Java file).

**Code samples or links to source code**

```
private fun baseSanitize(param: String) = param.replace(Regex("[^a-zA-Z0-9_-]"), "")
private fun baseSanitize(param: String) = param.replace("[^a-zA-Z0-9_-]".toRegex(), "")
private fun baseSanitize(param: String) = param.replace("\\W".toRegex(), "")
```

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

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

評価

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

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

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