Command Injection

Domain: Security

🎯 Motivation

Passing user input to shell commands lets attackers chain extra commands using ; or &&. Using safe APIs that avoid the shell entirely prevents this dangerous vulnerability.

πŸ“‹ Concrete Example

Avoid os.system(f"convert {filename} out.png"). A filename like a.png; rm -rf / is catastrophic. Use subprocess.run(["convert", filename, "out.png"]) with a list β€” no shell, no injection.

πŸ”— Analogy

Giving a courier a sealed package with an address label is safe. If you hand them a note saying β€œdeliver to A; also throw away everything at B,” you have given them two instructions.