Skip to interview prep
Apexed

30. What are XSS, CSRF and SQL injection, and how do you prevent them?

MediumWeb & APIs

Technical
Show model answer

XSS injects scripts into pages other users see: escape output, avoid raw HTML insertion, and use a Content Security Policy. CSRF tricks a logged-in browser into sending a request: use SameSite cookies, CSRF tokens, or bearer tokens not sent automatically.

SQL injection puts untrusted input into a query: always use parameterised queries or a safe ORM, and give the database account least privilege.

What are XSS, CSRF and SQL injection, and how do you prevent them — Software engineering interview question — Apexed