Reading Standard Input is security-sensitive. It has led in the past to the following vulnerabilities:
It is common for attackers to craft inputs enabling them to exploit software vulnerabilities. Thus any data read from the standard input (stdin) can be dangerous and should be validated.
This rule flags code that reads from the standard input.
You are at risk if you answered yes to this question.
Sanitize all data read from the standard input before using it.
class A { void foo(String fmt, Object args) throws Exception { // Sensitive. Check how the standard input is used. System.in.read(); // Sensitive. Check how safe this new InputStream is. System.setIn(new java.io.FileInputStream("test.txt")); java.io.Console console = System.console(); // Sensitive. All the following calls should be reviewed as they use the standard input. console.reader(); console.readLine(); console.readLine(fmt, args); console.readPassword(); console.readPassword(fmt, args); } }
All references to System.in
will create issues except direct calls to System.in.close()
.
Command line parsing libraries such as JCommander often read standard input when asked for passwords. However this rule doesn't raise any issue in this case as another hotspot rule covers command line arguments.
This rule is deprecated, and will eventually be removed.