Always apply in this order: sanitize, validate, escape
Purpose: Remove or modify dangerous content while preserving useful data. Sanitization transforms input to make it safe, but may lose information in the process. Needing to remove characters through sanitizing should not trigger any error response; save that for validation.
Warning: Sanitization alone is NOT enough! You must still escape output and validate input.
Vulnerability: Client-side validation only allows letters (a-z), but server-side validation allows letters AND numbers!
Try entering numbers in the form – they'll be blocked by input filter pattern attributes and JavaScript. Then use browser DevTools, curl, or an attack proxy to bypass client validation.
pattern="[a-z]+" attributecurl -X POST -d "username=user123" https://neo.hakr.site/validation.phpLesson: Never trust client-side validation! It's only for UX; Always validate on the server with the same rules.
Purpose: Display potentially dangerous content safely by encoding special characters.
Escaping preserves the original data but renders it harmless in the output context.