Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')

  • Rule ID: go_gosec_subproc_subproc
  • Languages: go
  • Source: subproc.yml


OS command injection is a perilous vulnerability that has the potential to lead to full system compromise. Adversaries may exploit this flaw by feeding arbitrary commands or arguments intended for execution. This opens the door for unchecked operations, which could wreak havoc on the system or reveal sensitive information.


✅ Avoid User Input in OS Commands

Always steer clear of incorporating user input when formulating commands or their arguments, especially for functions responsible for OS command execution. This includes, but is not limited to, filenames provided during user uploads/downloads.

✅ Hardcoded Argument Set

Ensure your application exclusively uses a hardcoded set of arguments for OS command executions. If filenames are being passed to such functions, consider adopting a hash of the filename or another distinctive identifier.

✅ Opt for Native Libraries

Due to the inherent risks associated with third-party commands and the possibility of undisclosed attack vectors, prefer using native libraries that offer the same capabilities as opposed to resorting to OS system commands.

✅ Specify Full Path in Windows

If the environment is Windows-based, always provide the complete path information when denoting the OS command. This circumvents potential vulnerabilities stemming from untrusted search paths (CWE-426).

userData := []byte("user data")
// create a temporary file in the application-specific directory
f, err := ioutil.TempFile("/var/app/restricted", "temp-*.dat")
if err != nil {

if _, err := f.Write(userData); err != nil {

if err := f.Close(); err != nil {

// use the absolute path to the binary and the name of the temporary file
// steering clear of any user-provided filenames
out, err := exec.Command("/bin/cat", f.Name()).Output()
if err != nil {


Associated CWE

OWASP Top 10


To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=go_gosec_subproc_subproc

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=go_gosec_subproc_subproc

Ready to take the next step? Learn more about Bearer Cloud.