BolEnglishLearn · Play · Win
Login

🧪 Security · Security Fundamentals

🧪

Input Validation

Security ControlCoreModule 6

Treat external input as untrusted and verify it.

Malformed or malicious input should not become commands or unsafe data.

💡 In practice

Validate IDs and use parameterized SQL rather than concatenating user input.

🖼️ CONCEPT PICTURE
A picture to help remember Input Validation
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.

💡 Learn🛠️ Apply🎯 Check

💡 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

1
Validate on the server
Re-check every input server-side, since a browser check can be bypassed.
2
Use parameterized queries
Pass user values as parameters so they can never be read as SQL commands.
3
Escape output by context
Encode data for HTML, URLs, or attributes so it displays as text, not code.
4
Allow, don't just block
Accept a known-good shape or list rather than trying to guess every bad input.

⚠️ 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.
⚠️ Common mistake: Building SQL by concatenating user input. Use parameterized queries so input is always treated as data, never as code.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 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. 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. 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.

🔑 Key terms

SQL injection
Tricking a query into running attacker-supplied commands.
XSS
Cross-site scripting: injecting script that runs in another user's browser.
Parameterized query
A query where user values are bound as data, not pasted into the text.
Allowlist
Accepting only values known to be safe, rejecting the rest.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →