github / github/codeql

Experimental CodeInjection query for JavaScript doesn't seem to work

Đang mở
#18,619 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
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ả

I noticed that the sources and sinks for some of the code injection CVEs in JavaScript were spread out among different queries making it difficult or impossible to find the issues in some cases. I also saw that there is an experimental suite of Javascript Security queries that add additional sources.

I tested the experimental query for code injection located [here](https://github.com/github/codeql/blob/edb9b47111518c0e3791a5db9d47f42e1476a487/javascript/ql/src/experimental/heuristics/ql/src/Security/CWE-094/CodeInjection.ql) on some simple js code that contains a use of `JSON.stringify` as source and `eval` as sink. I know this should be covered because there is a private class for `JSON.stringify` in the AdditionalSources.qll that CodeInjection.ql imports.

```
/**
* A use of `JSON.stringify`, viewed as a source for command-line injections
* since it does not properly escape single quotes and dollar symbols.
*/
private class JsonStringifyAsCommandInjectionSource extends HeuristicSource,
CommandInjection::Source instanceof JsonStringifyCall
{
override string getSourceType() { result = "a string from JSON.stringify" }
}

```

When I run it on this code, I get 0 results:

```
import fs from 'fs';

function encodeStatements(statements) {

eval(JSON.stringify(statements))

}

module.exports = encodeStatements;

```

I tested with this query to ensure that the sink was recognized which it was.

```

import javascript
import semmle.javascript.security.dataflow.CodeInjectionQuery
import CodeInjectionFlow::PathGraph
import semmle.javascript.heuristics.AdditionalSources

from DataFlow::Node sink
where CodeInjectionConfig::isSink(sink)
select sink, "Sink found"
```

When I tried the same thing for sources I got received 0 results in the source code. However I ran this query which confirmed that `JSON.stringify` is part of the sources added as HeuristicSource, so I'm very confused as to why this doesn't work.

```
import javascript
import semmle.javascript.security.dataflow.CodeInjectionQuery
import CodeInjectionFlow::PathGraph
import semmle.javascript.heuristics.AdditionalSources

from DataFlow::Node source
where source instanceof HeuristicSource
select source, "User input"

```

Not sure where the error here lies but I could use some help diagnosing it. Thanks!

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

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

Hướng nghiên cứu

Start with the experimental Security/CWE-094/CodeInjection.ql query and the AdditionalSources.qll definitions, then run the supplied JavaScript example and the two diagnostic queries. Done means determining why JSON.stringify is not recognized as a source in the CodeInjection query and documenting or correcting that behavior so the example produces the expected result.

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

Đánh giá

Công nghệ
javascript
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.