Skip to content

OS Command Injection

Description

OS command injection is a critical vulnerability that can lead to a full system compromise as it may allow an adversary to pass in arbitrary commands or arguments to be executed. User input should never be used in constructing commands or command arguments to functions which execute OS commands.

Examples

Insecure Code

go
exec.CommandContext(ctx, userSuppliedInput)

Secure Code

go
out, err := exec.Command("/bin/cat", f.Name()).Output()

Remediation

Use a hardcoded set of arguments that are to be passed to OS commands. If filenames are being passed to these functions, use a hash of the filename or some other unique identifier. Consider using a native library that implements the same functionality instead of using OS system commands.

Rule Details

FieldValue
IDCODE-0796
CategoryInjection
SeverityCRITICAL
CWECWE-78
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
Tagsos-command-injection, injection
OWASPA1:2017-Injection, A03:2021-Injection