github / github/codeql

False negative: java string concatenation using StringBuilder causing injection

Đang mở
#12,939 6 bình luận 0 reaction 0 người được giao Xem trên GitHub
Java question
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 issue**

CodeQL correctly detected a Java code issue that involved Java string concatenation being passed to `Runtime.getRuntime().exec("")`. In our case it wasn't exploitable, but it was still dangerous code that needed to be remediated.

**Code samples**
The code (not mine!) looked a bit like like this:
`Process p = Runtime.getRuntime().exec("python " + SCRIPT_PATH + " --file " + inputFile.getAbsolutePath());`

The developer attempted to correct the issue on their own and changed it to this:
```
StringBuilder pythonPath = new StringBuilder();
pythonPath.append("python ").append(SCRIPT_PATH).append(" --file ").append(inputFile.getAbsolutePath());
Process p = Runtime.getRuntime().exec(pythonPath.toString());
```

CodeQL closed the alert as fixed, even though the new code is still vulnerable and logically the same.

It appears as though CodeQL is not properly detecting Java string concatenation vulnerabilities whenever the `StringBuilder` class is used. `StringBuilder` is fairly common, so this results in some risky omissions.

**CodeQL Rule**
Rule ID: java-concatenated-command-line

**Build-Time Environment**
Language: java
Java Distribution: temurin
Java Version: 8 (via `setup-java@v3`)
Java Build Tool: Maven 3.8.2

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.