Environment variable injection query documentation

This commit is contained in:
Ed Minnix
2023-11-15 12:02:17 -05:00
parent f1f0f50c92
commit 1550f5df2a
3 changed files with 47 additions and 0 deletions

View File

@@ -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>

View File

@@ -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();
}

View File

@@ -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();
}