Open
Description
The thing is, if I have this code:
JSON.parse = function(text, reviver) {
j = eval("(" + text + ")");
};
JSON.parse(window.location.href);
CodeQL reported an alert:
"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
:
JSON.parse = function(text, reviver) {
j = eval("(" + text + ")");
};
./main.js
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.