Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing code injection TP in JavaScript rule #18979

Open
Anemone95 opened this issue Mar 11, 2025 · 3 comments
Open

Missing code injection TP in JavaScript rule #18979

Anemone95 opened this issue Mar 11, 2025 · 3 comments
Labels
acknowledged GitHub staff acknowledges this issue JS question Further information is requested

Comments

@Anemone95
Copy link

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.

@Anemone95 Anemone95 added the question Further information is requested label Mar 11, 2025
@hvitved
Copy link
Contributor

hvitved commented Mar 12, 2025

@github/codeql-javascript : Would you be able to take a look, please?

@asgerf asgerf added the acknowledged GitHub staff acknowledges this issue label Mar 12, 2025
@asgerf
Copy link
Contributor

asgerf commented Mar 12, 2025

Hi @Anemone95. Thanks for the report.

This is a known limitation in the analysis at the moment. It occurs when a global access path is assigned in multiple files, or as in this case, a global access path assignment clashes with a built-in function.

@Anemone95
Copy link
Author

I see. I thought it similarly, maybe as a trade-off for precision and scalability. Thanks for your answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged GitHub staff acknowledges this issue JS question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants