mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Environment variable injection query documentation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
<overview>
|
||||
<p>Passing unvalidated user input into the environment variables of a subprocess can allow an attacker to execute malicious code.</p>
|
||||
</overview>
|
||||
|
||||
<recommendation>
|
||||
<p>If possible, use hard-coded string literals to specify the environment variable or its value.
|
||||
Instead of passing the user input directly to the
|
||||
process or library function, examine the user input and then choose
|
||||
among hard-coded string literals.</p>
|
||||
|
||||
<p>If the applicable environment variables cannot be determined at
|
||||
compile time, then add code to verify that the user input string is
|
||||
safe before using it.</p>
|
||||
</recommendation>
|
||||
|
||||
<example>
|
||||
<p>In the following (BAD) example, the environment variable <code>PATH</code> is set to the value of the user input <code>path</code> without validation.</p>
|
||||
|
||||
<sample src="ExecTaintedEnvironmentValue.java" />
|
||||
|
||||
<p>In the following (BAD) example, an environment variable is set with a name that is derived from the user input <code>var</code> without validation.</p>
|
||||
|
||||
<sample src="ExecTaintedEnvironmentName.java" />
|
||||
|
||||
</example>
|
||||
</qhelp>
|
||||
@@ -0,0 +1,9 @@
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
String attr = request.getParameter("attribute");
|
||||
String value = request.getParameter("value");
|
||||
|
||||
Map<String, String> env = processBuilder.environment();
|
||||
env.put(attribute, value);
|
||||
|
||||
processBuilder.start();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
String path = request.getParameter("path");
|
||||
|
||||
Map<String, String> env = processBuilder.environment();
|
||||
env.put("PATH", path);
|
||||
|
||||
processBuilder.start();
|
||||
}
|
||||
Reference in New Issue
Block a user