Web Security & WAF interview question · Most asked
What is CSRF and how do you defend against it?
Summary
Cross-Site Request Forgery tricks a logged-in user's browser into sending an unwanted state-changing request to your site, because browsers automatically attach cookies. Defend with SameSite cookies, anti-CSRF tokens, Origin/Referer checks, and never changing state on GET.
Longer Answer
Token-based APIs using the Authorization header aren't vulnerable because browsers don't attach those headers automatically. Frameworks include CSRF middleware (Django, Laravel, Spring Security, Flask-WTF).
Key Points
- Exploits automatic cookies
- SameSite=Lax/Strict
- Synchronizer or double-submit tokens
- Origin checks
- No state change on GET
More most-asked Web Security & WAF questions
- What is the OWASP Top 10 and which risks does it currently highlight?
- What is SQL injection and how do you prevent it?
- What is Cross-Site Scripting (XSS) and how do you prevent it?
- What is a Web Application Firewall (WAF), and what can and can't it do?
- How do rate-limiting algorithms work (fixed window, sliding window, token bucket)?
- What is SSRF (Server-Side Request Forgery) and how do you prevent it?