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.