Fix GuideInjection

How to Fix CWE-78: OS Command Injection

Verified by Precogs Threat Research

The application passes untrusted input to system shell commands without proper sanitization.

⚠️ Impact if Unpatched

Full server compromise, arbitrary OS command execution, data exfiltration, pivot point for network attacks.

Step-by-Step Remediation

  1. Use language-native APIs instead of shell commands (e.g., fs.rename instead of mv)
  2. If shell commands are unavoidable, use parameterized execution (subprocess with list args)
  3. Never pass user input directly to shell interpreters
  4. Implement strict input validation with allowlists
  5. Run applications with minimal OS privileges

Code Example

❌ Vulnerable

# VULNERABLE: Shell injection
os.system(f"ping {user_input}")

✅ Fixed

# SAFE: Parameterized subprocess
subprocess.run(["ping", "-c", "1", user_input], shell=False)

Don't just patch one instance.

Scan your entire codebase for all instances of OS Command Injection.

Scan for Free with Precogs AI →

Recent Vulnerabilities (CWE-78)

46 vulnerabilities in our database match OS Command Injection.

View all 46 vulnerabilities →