Skip to content

Missing code injection TP in JavaScript rule #18979

Open
@Anemone95

Description

@Anemone95

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    JSacknowledgedGitHub staff acknowledges this issuequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions