cwe-78-os-command-injection

Replace insecure Java OS command execution with validated ProcessBuilder usage.

3|1|Updated Mar 6, 2026
One-click install
npx skills add https://github.com/DevelopersCoffee/java-cwe-security-skills --skill cwe-78-os-command-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cwe-78-os-command-injection
Source: https://github.com/DevelopersCoffee/java-cwe-security-skills/tree/main/cwe-78-os-command-injection
Command: npx skills add https://github.com/DevelopersCoffee/java-cwe-security-skills --skill cwe-78-os-command-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses vulnerabilities arising from the improper neutralization of OS commands in Java applications, preventing potential command injection attacks.

Core Features & Use Cases

  • Vulnerability Remediation: Identifies and provides secure alternatives for code that executes OS commands with user-controlled input.
  • Secure Coding Practices: Guides developers towards using safer methods like ProcessBuilder and input validation.
  • Use Case: When a SAST tool flags a Runtime.getRuntime().exec() call that uses external input, this Skill can be invoked to refactor the code into a secure ProcessBuilder implementation with input sanitization.

Quick Start

Use the cwe-78-os-command-injection skill to secure the provided Java code snippet that executes an OS command.

Frequently Asked Questions about cwe-78-os-command-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix OS command injection vulnerabilities flagged by SAST tools in Java?

To fix OS command injection vulnerabilities flagged by SAST in Java, replace insecure Runtime.getRuntime().exec() calls with validated ProcessBuilder usage. This remediates CWE-78 findings by enforcing input validation and secure process execution.

What is CWE-78 improper neutralization of OS commands in Java?

CWE-78 improper neutralization of OS commands occurs when Java applications execute OS commands using user-controlled input without validation. This vulnerability allows potential command injection attacks if external input is passed directly to command execution functions.

How do I use ProcessBuilder to securely execute OS commands with external input?

To use ProcessBuilder securely with external input, separate the command and its arguments into individual array elements rather than a single concatenated string. You must also implement strict input validation and sanitization before passing parameters to the ProcessBuilder.

Is Runtime.getRuntime().exec() vulnerable to command injection when using external input?

Yes, Runtime.getRuntime().exec() is vulnerable to command injection when invoked with user-controlled input. SAST tools frequently flag this pattern, requiring remediation through secure ProcessBuilder alternatives and input validation to prevent attacks.

What is the best way to remediate CWE-78 command injection findings during a security review?

The best way to remediate CWE-78 command injection findings during a security review is to refactor insecure command execution code into secure ProcessBuilder implementations. This requires input validation and secure process execution to fully mitigate injection risks.