Skip to content

Commit 938d52b

Browse files
Docs review suggestions
Co-authored-by: Felicity Chapman <[email protected]>
1 parent a528db8 commit 938d52b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

java/ql/src/Security/CWE/CWE-078/ExecTaintedEnvironment.qhelp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ safe before using it.</p>
2525
<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>
2626

2727
<sample src="ExecTaintedEnvironmentName.java" />
28+
<p>In the following (GOOD) example, the user's input is validated before being used to set the environment variable.</p>
2829

30+
<sample src="ExecTaintedEnvironmentValidated.java" />
31+
32+
<p>In the following (GOOD) example, the user's input is checked and used to determine an environment variable to add.</p>
33+
34+
<sample src="ExecTaintedEnvironmentChecked.java" />
2935
</example>
3036
</qhelp>

java/ql/src/Security/CWE/CWE-078/ExecTaintedEnvironment.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Building a command with an injected environment variable
3-
* @description Using externally controlled strings in the environment variables
4-
* passed to a command line is vulnerable to malicious changes to the
3+
* @description Passing environment variables containing externally controlled
4+
* strings to a command line is vulnerable to malicious changes to the
55
* environment of a subprocess.
66
* @problem.severity error
77
* @kind path-problem
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Map<String, String> env = builder.environment();
2+
String debug = request.getParameter("debug");
3+
4+
if (debug != null) {
5+
env.put("PYTHONDEBUG", "1");
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
String opt = request.getParameter("opt");
2+
String value = request.getParameter("value");
3+
4+
Map<String, String> env = processBuilder.environment();
5+
6+
// GOOD: opt and value are checked before being added to the environment
7+
if (permittedJavaOptions.contains(opt) && validOption(opt, value)) {
8+
env.put(opt, value);
9+
}

0 commit comments

Comments
 (0)