Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/CommandInjection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// https://documentation.blackduck.com/bundle/coverity-docs/page/checker-ref/checkers/NO/os_cmd_injection.html

import java.io.*;
import javax.servlet.http.HttpServletRequest;

public class CommandInjection {
public static Process runCmd(HttpServletRequest request) throws IOException {
String filename = request.getParameter("filename");
ProcessBuilder builder = new ProcessBuilder("cat", filename);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-generated PR comment (Coverity)

Coverity Issue - OS Command Injection

High CWE-78
Calling "ProcessBuilder". Passing the tainted value "{"cat", filename}" to the process-invoking API may allow an attacker to modify the intention of the command.

A user can change the intent of an operating system command. This change may result in the disclosure, destruction, or modification of sensitive data or operating system resources.

How to fix

Ensure the tainted data cannot modify the intent of the OS command. If possible, use a safer library or API call instead.

Process process = builder.start();
return(process);
}
}
Loading