Skip to content
BENIBIX Learn

Input Validation

Development🔐 SecuritySecurity Basics

Also known as Validation, Validating Input, Data Validation

Making sure what users send fits the rules. Then your code uses it.

Think of it like

Think of it like a bouncer checking tickets. Only the right kind of thing gets through the door.

Example

Lucy's sign-up form asks for an age. Someone sends minus 5 straight to her API, and the server answers 400 Bad Request instead of saving it.

Why it matters

Most attacks start with input the code did not expect. Checking it first stops whole kinds of bug.

Definition

Input validation checks outside data against rules before your code uses it. An age should be a whole number between 0 and 150. An email should look like an email. Anything that breaks the rules is turned away with a clear message. Checks in the browser are only for comfort; the server must check again, because anyone can skip the page.

Common mistake

Checking input only in the browser. Anyone can send a request straight to the server, with any data at all.

Key takeaways

  1. 1
    Check before use. Every outside input.
  2. 2
    Allow the good. Not just block the bad.
  3. 3
    On the server. Always, every time.

Compare

Learn it properly