github / github/codeql

Missing code injection TP in JavaScript rule

Open
#18,979 3 comments 0 reactions 0 assignees View on GitHub
acknowledged JS question
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

The thing is, if I have this code:
```javascript
JSON.parse = function(text, reviver) {
j = eval("(" + text + ")");
};
JSON.parse(window.location.href);
```
CodeQL reported an alert:
```csv
"Code injection","Interpreting unsanitized user input as code allows a malicious user arbitrary code execution.","error","This code execution depends on a [[""user-provided value""|""relative:///test.js:5:12:5:31""]].","/test.js","3","14","3","29"
```
But if I separate the file saying:
`./lib1.js`:
```javascript
JSON.parse = function(text, reviver) {
j = eval("(" + text + ")");
};
```
`./main.js`
```javascript
require("./lib1");
// JSON.parse = function(text, reviver) {
// j = eval("(" + text + ")");
// };
JSON.parse(window.location.href);
```
I can't get that alert anymore. Why did that happen?

I was using codeql and query pack version release 2.20.4.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.