Introduction
Imagine a website that accepts information from users. Without checking this information carefully, harmful data could cause problems or security risks. Input validation and sanitization help stop bad data from causing trouble.
Jump into concepts and practice - no test required
Think of a security guard at a building entrance checking visitors. The guard first checks if the visitor has a valid ID (validation). Then, the guard makes sure the visitor doesn’t carry any dangerous items by inspecting their bag (sanitization). Both steps keep the building safe.
┌─────────────────────┐
│ User Input Data │
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ Input Validation │
│ (Check rules/format)│
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ Input Sanitization │
│ (Clean harmful data) │
└─────────┬───────────┘
│
▼
┌─────────────────────┐
│ Safe Data for Use │
└─────────────────────┘input validation in cybersecurity?user_input = "" safe_input = sanitize(user_input) print(safe_input)If
sanitize removes all HTML tags, what will be printed?def validate_email(email):
return '@' in email and '.' in email
What is the main problem with this validation?