Skip to content

Commit 1550f5d

Browse files
committed
Environment variable injection query documentation
1 parent f1f0f50 commit 1550f5d

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
<overview>
6+
<p>Passing unvalidated user input into the environment variables of a subprocess can allow an attacker to execute malicious code.</p>
7+
</overview>
8+
9+
<recommendation>
10+
<p>If possible, use hard-coded string literals to specify the environment variable or its value.
11+
Instead of passing the user input directly to the
12+
process or library function, examine the user input and then choose
13+
among hard-coded string literals.</p>
14+
15+
<p>If the applicable environment variables cannot be determined at
16+
compile time, then add code to verify that the user input string is
17+
safe before using it.</p>
18+
</recommendation>
19+
20+
<example>
21+
<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>
22+
23+
<sample src="ExecTaintedEnvironmentValue.java" />
24+
25+
<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>
26+
27+
<sample src="ExecTaintedEnvironmentName.java" />
28+
29+
</example>
30+
</qhelp>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public void doGet(HttpServletRequest request, HttpServletResponse response) {
2+
String attr = request.getParameter("attribute");
3+
String value = request.getParameter("value");
4+
5+
Map<String, String> env = processBuilder.environment();
6+
env.put(attribute, value);
7+
8+
processBuilder.start();
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public void doGet(HttpServletRequest request, HttpServletResponse response) {
2+
String path = request.getParameter("path");
3+
4+
Map<String, String> env = processBuilder.environment();
5+
env.put("PATH", path);
6+
7+
processBuilder.start();
8+
}

0 commit comments

Comments
 (0)