Cross-Site Request Forgery (CSRF)
Cross-Site Request Forgery (CSRF) is a web security vulnerability that forces a user's browser to perform unwanted actions on a web application in which they are authenticated. CSRF attacks exploit the trust that web applications have for authenticated users and can result in unauthorized data modification, unauthorized transaction execution, or even account takeover. Defending against CSRF attacks involves implementing proper anti-CSRF tokens, verifying the origin of requests, and following the principle of least privilege.
Guide on Cross-Site Request Forgery (CSRF)
How CSRF Works:
1. The attacker creates a malicious link containing a command that they wish to force the user to execute.
2. This link is then sent to the user, usually embedded within an innocuous-looking website or an email.
3. If the user clicks on the link while being authenticated on the target site, the command is silently executed using the user's credentials.
4. The website can't distinguish between a legitimate request from the user and a forged request.
Exam Tips - Answering Questions on Cross-Site Request Forgery (CSRF):
While answering exam questions related to CSRF, keep in mind that you need to:
- Understand the basic mechanics of CSRF attacks.
- Know the prevention methods, such as using anti-CSRF tokens or Same Site Cookies.
- Be able to explain how it's different from Cross-Site Scripting (XSS), as XSS involves injecting malicious code into websites, while CSRF involves tricking the client into executing a command that benefits the attacker.
CompTIA Security+ - Cross-Site Request Forgery (CSRF) Example Questions
Test your knowledge of Cross-Site Request Forgery (CSRF)
Question 1
A company has implemented a password reset form that includes a secret question and answer as part of the process. An attacker can reset a victim's password by submitting a CSRF attack with a forged password reset request. What method can the developer use to prevent this attack?
Question 2
An e-commerce website allows users to view their order history. After logging in, a user can access the order history page by clicking the "viewOrder?id=xxx" link. An attacker sends a victim an email with an image element pointing to the "viewOrder?id=yyy" URL. How can the developer mitigate this potential CSRF attack?
Question 3
A social media website's "like" feature uses a link in the following format: "like.php?post_id=123456". An attacker sends a link to the victim's email with the same URL format to trick the user into liking a malicious post. What measure can the developer implement to prevent abuse of this "like" feature?