🧪 Security · Security Fundamentals
Input Validation
Treat external input as untrusted and verify it.
Malformed or malicious input should not become commands or unsafe data.
Validate IDs and use parameterized SQL rather than concatenating user input.
💡 Like a bouncer checking every guest at the door: nobody gets in just because they showed up and looked confident.
💡 Why it matters
Most classic attacks, from SQL injection to cross-site scripting, come from trusting input that an attacker controls. If raw input becomes a command, the attacker runs it. Validating and safely handling input closes the door on a huge class of exploits.
🛠️ How to achieve it
⚠️ Signs of trouble
- •SQL is built by gluing strings and user input together.
- •User text appears on the page without being escaped.
- •Validation exists only in JavaScript in the browser.
- •Uploaded files are trusted by their name or extension alone.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. What is the safe way to use user input in a database query?
Answer: Parameterized queries that bind input as data
Parameterized queries keep user values as data, so they can never be interpreted as SQL commands.
2. Why is browser-only validation not enough?
Answer: An attacker can bypass the browser and call the server directly
Client-side checks are easily skipped, so every input must be re-validated on the server.
3. User text is shown on a page without escaping. What risk does this create?
Answer: Cross-site scripting (XSS)
Unescaped user content can carry script that runs in other users' browsers, the classic XSS flaw.
