ryandens / semgrep-test

0 stars 1 forks source link

Introduced protections against system command injection #10

Closed pixee-ryandens[bot] closed 4 months ago

pixee-ryandens[bot] commented 4 months ago

This change hardens all instances of Runtime#exec() to offer protection against attack.

Left unchecked, Runtime#exec() can execute any arbitrary system command. If an attacker can control part of the strings used to as program paths or arguments, they could execute arbitrary programs, install malware, and anything else they could do if they had a shell open on the application host.

Our change introduces a sandbox which protects the application:

+ import io.github.pixee.security.SystemCommand;
  ...
- Process p = Runtime.getRuntime().exec(command);
+ Process p = SystemCommand.runCommand(Runtime.getRuntime(), command);

The default restrictions applied are the following:

There are more options for sandboxing if you are interested in locking down system commands even more.

:x: The following packages couldn't be installed automatically, probably because the dependency manager is unsupported. Please install them manually:

Gradle dependencies { implementation("io.github.pixee:java-security-toolkit:1.1.3") }
Maven io.github.pixee java-security-toolkit 1.1.3
More reading * [https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html](https://cheatsheetseries.owasp.org/cheatsheets/OS_Command_Injection_Defense_Cheat_Sheet.html) * [https://wiki.sei.cmu.edu/confluence/display/java/IDS07-J.+Sanitize+untrusted+data+passed+to+the+Runtime.exec%28%29+method](https://wiki.sei.cmu.edu/confluence/display/java/IDS07-J.+Sanitize+untrusted+data+passed+to+the+Runtime.exec%28%29+method)

🧚🤖Powered by Pixeebot (codemod ID: pixee:java/harden-process-creation)