sdomde213606 (Community Member) asked a question.

OS Command Injection used in an OS Command ('OS Command
Injection') (CWE ID 78)(1 flaw) Java code

List<String> commandList = Arrays.asList(commandArray);

ProcessBuilder pb = new ProcessBuilder(commandList);

Process process = pb.start();

 

Getting error at 2nd line ProcessBuilder(commandList);


  • Anthony Fielding (Veracode)

    Hi @sdomde213606 (Community Member)​,

    Thanks for your question.

     

    The flaw is being raised because the commandArray parameter contains data from an untrusted source, such as an HTTP request, a configuration file or database. Where possible the recommendation is to not allow the end user or consumer of the service to arbitrarily specify the executable or it's parameters to prevent malicious input from being injected and executed. If you must rely on data from untrusted sources, sufficient validation must be in place such as the use of allow-lists to mitigate the flaw.

     

    I answered a similar question to this yesterday which may be useful for you: https://community.veracode.com/s/question/0D52T000054VCt8SAG/whats-causing-an-os-command-injectioncwe78-flaw-in-the-following-c-code.

     

    Please note that Veracode Static Analysis is unable to verify the changes you have made sufficiently remove the risk from taking untrusted user input and executing it. The resolution for each instance is contextual to how the application processes the untrusted input, and so you will always be required to propose a mitigation. Such proposal should clearly state all the controls in place to mitigate the risk.

     

    I hope that answers your question.

     

    Thanks,

    Anthony Fielding

    Expand Post

Topics (1)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.