Q1. What is a CSRF attack and why does it work?
CSRF (Cross-Site Request Forgery) is an attack where a page you did not write tricks a logged-in user's browser into sending a state-changing request to a site they are authenticated on. It works because browsers automatically attach cookies (including session cookies) to any request bound for the cookie's domain, even when the request is triggered from another origin. The server sees a valid session and executes the action, unaware the user never intended it.