File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
java/ql/src/experimental/Security/CWE/CWE-078 Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ class Test {
2+ public static void main (String [] args ) {
3+ String script = System .getenv ("SCRIPTNAME" );
4+ if (script != null ) {
5+ // BAD: The script to be executed is controlled by the user.
6+ Runtime .getRuntime ().exec (script );
7+ }
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE qhelp PUBLIC
2+ "-//Semmle//qhelp//EN"
3+ "qhelp.dtd">
4+ <qhelp >
5+ <overview >
6+ <p >Code that passes user input directly to <code >Runtime.exec</code >, or
7+ some other library routine that executes a command, allows the
8+ user to execute malicious code.</p >
9+
10+ </overview >
11+ <recommendation >
12+
13+ <p >If possible, use hard-coded string literals to specify the command to run
14+ or library to load. Instead of passing the user input directly to the
15+ process or library function, examine the user input and then choose
16+ among hard-coded string literals.</p >
17+
18+ <p >If the applicable libraries or commands cannot be determined at
19+ compile time, then add code to verify that the user input string is
20+ safe before using it.</p >
21+
22+ </recommendation >
23+ <example >
24+
25+ <p >The following example shows code that takes a shell script that can be changed
26+ maliciously by a user, and passes it straight to <code >Runtime.exec</code >
27+ without examining it first.</p >
28+
29+ <sample src =" ExecTainted.java" />
30+
31+ </example >
32+ <references >
33+
34+ <li >
35+ OWASP:
36+ <a href =" https://www.owasp.org/index.php/Command_Injection" >Command Injection</a >.
37+ </li >
38+ <li >SEI CERT Oracle Coding Standard for Java:
39+ <a href =" https://wiki.sei.cmu.edu/confluence/display/java/IDS07-J.+Sanitize+untrusted+data+passed+to+the+Runtime.exec()+method" >IDS07-J. Sanitize untrusted data passed to the Runtime.exec() method</a >.</li >
40+
41+
42+
43+ <!-- LocalWords: CWE untrusted unsanitized Runtime
44+ -->
45+
46+ </references >
47+ </qhelp >
You can’t perform that action at this time.
0 commit comments