Visitar URL original
JS: second-order-command-injection by erik-krogh · Pull Request #11013 · github/codeql · GitHub
The Wayback Machine - https://web.archive.org/web/20221029100336/https://github.com/github/codeql/pull/11013
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

JS: second-order-command-injection #11013

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Oct 27, 2022 •

CVE-2022-25900: FN (dynamically chosen git cmd).
CVE-2022-24437: TP/TN
CVE-2022-25865: TP/TN
CVE-2022-24066: FN (we don't recognize the source due to very dynamic initialization, and we don't recognize the sink due to some dynamic command construction).
CVE-2022-1440: FN (this is more for js/shell-command-constructed-from-input, but they roll their own shell sanitization, which it doens't track through).
CVE-2022-25766: FN (dynamic construction of the arguments).
CVE-2022-24433: FN (same project as CVE-2022-24066).

@erik-krogh erik-krogh added the WIP This is a work-in-progress, do not merge yet! label Oct 27, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 27, 2022

QHelp previews:

javascript/ql/src/Security/CWE-078/SecondOrderCommandInjection.qhelp

Second order command injection

Some shell commands, like git ls-remote, can execute arbitrary commands if a user provides a malicious URL that can start with --upload-pack. This can be used to execute arbitrary code on the server.

Recommendation

Sanitize user input before passing it to the shell command by for example ensuring that URLs are valid and do not contain malicious commands.

Example

The following example shows code that executes git ls-remote on a URL that can be controlled by a malicious user.

const express = require("express");
const app = express();

const cp = require("child_process");

app.get("/ls-remote", (req, res) => {
  const remote = req.query.remote;
  cp.execFile("git", ["ls-remote", remote]); // NOT OK
});

The problem has been fixed in the below where the URL is validated before being passed to the shell command.

const express = require("express");
const app = express();

const cp = require("child_process");

app.get("/ls-remote", (req, res) => {
  const remote = req.query.remote;
  if (!(remote.startsWith("git@") || remote.startsWith("https://"))) {
    throw new Error("Invalid remote: " + remote);
  }
  cp.execFile("git", ["ls-remote", remote]); // OK
});

References

Labels
documentation JS WIP This is a work-in-progress, do not merge yet!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant