Command Injection
ELI5 — The Vibe Check
Command injection is like SQL injection but worse — instead of attacking your database, the hacker injects shell commands that run on your actual server. If your code runs user input in a terminal command without sanitizing, an attacker could run rm -rf / on your production server.
Real Talk
Command injection occurs when user-controlled input is passed unsanitized to a shell command. Attackers can execute arbitrary OS commands with the application's privileges. Prevention involves avoiding shell execution with user input, using APIs with argument lists instead of shell strings, and strict input validation.
Show Me The Code
// ❌ Vulnerable: user input goes into shell command
import { exec } from 'child_process';
exec(`ping ${userInput}`); // if userInput = '8.8.8.8; rm -rf /', you're done
// ✅ Safe: use argument arrays, not shell strings
import { execFile } from 'child_process';
execFile('ping', ['-c', '4', userInput], callback);
When You'll Hear This
"The image resizer was vulnerable to command injection via the filename." / "Never pass user input directly to exec()."
Related Terms
Input Validation
Input validation is checking that user input is what you expect before using it.
OWASP Top 10
The OWASP Top 10 is the security industry's greatest hits of web vulnerabilities — the 10 most common, dangerous ways apps get hacked.
Sanitization
Sanitization is cleaning up user input before using it — stripping out anything dangerous like script tags or SQL commands.
SQL Injection
SQL injection is when a hacker types SQL code into a text field instead of normal text, and your stupid database runs it.
XSS (XSS)
XSS stands for Cross-Site Scripting. Hackers inject their own JavaScript into your site so when other users visit, the evil script runs in their browser.