command injection

An attack where input meant as data, such as a file name or form field, gets run as commands because a program built code from it.

An attacker who can inject commands runs anything the script's user is allowed to run.

In more detail

It happens when untrusted text is pasted into a command string that a shell or interpreter then parses, for example through eval or sh -c. Escaping special characters is a losing denylist; the fix is never to turn data into code, passing values as separate arguments instead.

Example

subprocess.run(f"echo resizing {name}", shell=True) with name = "x; id" runs id

Related terms

Taught in

References