github / github/codeql

False positive - Ruby (on Rails) - SQL query built from user-controlled sources

Đang mở
#14,670 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
false-positive
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**

I'm seeing this pop up when query methods (e.g., `find_by`) are passed a `hash` (or `ActionController::Parameters` object) that is derived directly from `params`. Since a hash is properly escaped by the library (ActiveRecord), this is a false positive. While the below example is trivial, I've seen multiple closed source repos at our company with many columns `.permit`ted and it would be onerous to change them all to hash literals with keys as literals and values pulled from `params`. An important point is that `find_by(id: params[:id])` and `find_by(params.permit(:id).to_h)` produce exactly the same argument to `find_by`, yet the former is "good" while the latter receives an alert.

**Code samples or links to source code**

False positive with `params.permit`: https://github.com/Cohen-Carlisle/demo-codeql-sqli/blob/95669d7bb5adc0d8cc584bcf306776b6d712f99f/app/controllers/posts_controller.rb
Trying various combinations of `slice` and `to_h` didn't resolve the alert ([to_h](https://github.com/Cohen-Carlisle/demo-codeql-sqli/blob/ab7d9a7b890c38e25254be809fd020b9625cc0ce/app/controllers/posts_controller.rb#L63), [slice on params](https://github.com/Cohen-Carlisle/demo-codeql-sqli/blob/f0e2ea8602071eebb0a2b92b39e7c3e804767df2/app/controllers/posts_controller.rb#L63), [to_h after slice](https://github.com/Cohen-Carlisle/demo-codeql-sqli/blob/2c96cbcdfd15747ebb3af4311ae3ad6a6205e962/app/controllers/posts_controller.rb#L63), [slice after to_h](https://github.com/Cohen-Carlisle/demo-codeql-sqli/blob/c6b630aef06b50d98ef9b7afdb3577ef9157f5da/app/controllers/posts_controller.rb#L63)).
What CodeQL accepts: https://github.com/Cohen-Carlisle/demo-codeql-sqli/blob/42b14f8d5b273e61c9f364168e34364552c10821/app/controllers/posts_controller.rb#L63

**URL to the alert on GitHub code scanning (optional)**

https://github.com/Cohen-Carlisle/demo-codeql-sqli/security/code-scanning/1

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.