github / github/codeql

Missing code injection TP in JavaScript rule

Abierto
#18,979 3 comentarios 0 reacciones 0 asignados Ver en GitHub
acknowledged JS question
Lenguaje dominante
CodeQL
Estrellas
10.1k
Forks
2.1k
Merge medio
2 d 15 h
PR fusionados (30 d)
141

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.