-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
JS: Env Injection query #15060
JS: Env Injection query #15060
Conversation
Hello am0o0 👋 In the meantime, feel free to make changes to the pull request. If you'd like to maximize payout for your this and future submissions, here are a few general guidelines, that we might take into consideration when reviewing a submission.
Please note that these are guidelines, not rules. Since we have a lot of different types of submissions, the guidelines might vary for each submission. Happy hacking! |
hi, sorry if I updated this query after changing the state from draft, according my latest review I learned mannythings and I applied my learnings in here too. |
QHelp previews: javascript/ql/src/experimental/Security/CWE-099/EnvValueAndKeyInjection.qhelperrors/warnings:
javascript/ql/src/experimental/Security/CWE-099/EnvValueInjection.qhelperrors/warnings:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're restricting your query to only find results where the same source flows to both the value and key of environment variable write.
The sources should not be shared between the two dataflow configurations.
But you're not restricting that it's the same write to process.env
.
So you can have one write like: process.env[tainted] = "constant"
, and another like: process.env.constant = tainted
, and the second write would get flagged because the first exist somewhere else.
You should make a predicate that relate the key and value of the write to process.env
, and then use that to make sure it's the same write to process.env
you're finding.
Something like:
private predicate readToProcessEnv(DataFlow::Node key, DataFlow::Node value) {
exists(DataFlow::PropWrite env | env = NodeJSLib::process().getAPropertyWrite("env") |
key = env.getPropertyNameExpr().flow() and
value = env.getRhs()
)
}
Also, there are some errors with the QHelp.
I havne't look at those yet, but this is the errors from the CI:
/home/runner/work/codeql/codeql/javascript/ql/src/experimental/Security/CWE-099/EnvValueAndKeyInjection.qhelp:33:78: element "a" not allowed here; expected the element end-tag or element "li"
/home/runner/work/codeql/codeql/javascript/ql/src/experimental/Security/CWE-099/EnvValueInjection.qhelp:33:78: element "a" not allowed here; expected the element end-tag or element "li"
…stead of API nodes to find env key and value assignments, fix a bug thanks to @erik-krogh
javascript/ql/test/experimental/Security/CWE-099/EnvValueAndKeyInjection/test.js
Outdated
Show resolved
Hide resolved
QHelp previews: javascript/ql/src/experimental/Security/CWE-099/EnvValueAndKeyInjection.qhelperrors/warnings:
javascript/ql/src/experimental/Security/CWE-099/EnvValueInjection.qhelperrors/warnings:
|
javascript/ql/src/experimental/Security/CWE-099/EnvValueAndKeyInjection.qhelp
Outdated
Show resolved
Hide resolved
QHelp previews: javascript/ql/src/experimental/Security/CWE-099/EnvValueAndKeyInjection.qhelpUser controlled arbitrary environment variable injectionControlling the value of arbitrary environment variables from user-controllable data is not safe. RecommendationRestrict this operation only to privileged users or only for some not important environment variables. ExampleThe following example allows unauthorized users to assign a value to any environment variable. const http = require('node:http');
http.createServer((req, res) => {
const { EnvValue, EnvKey } = req.body;
process.env[EnvKey] = EnvValue; // NOT OK
res.end('env has been injected!');
}); References
javascript/ql/src/experimental/Security/CWE-099/EnvValueInjection.qhelpUser controlled environment variable value injectionAssigning Value to environment variables from user-controllable data is not safe. RecommendationRestrict this operation only to privileged users or only for some not important environment variables. ExampleThe following example allows unauthorized users to assign a value to a critical environment variable. const http = require('node:http');
http.createServer((req, res) => {
const { EnvValue } = req.body;
process.env["A_Critical_Env"] = EnvValue; // NOT OK
res.end('env has been injected!');
}); References
|
Detect user-controllable environment variable injection that can lead to security issues.