Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is Cross-site request forgery (CSRF)?
CSRF is a type of cyber attack where a malicious website tricks a user's browser into performing unwanted actions on a trusted site where the user is logged in.
Click to reveal answer
beginner
How does a CSRF attack typically work?
An attacker creates a fake request that looks legitimate and tricks the user's browser into sending it to a trusted website, causing actions like changing passwords or making purchases without the user's consent.
Click to reveal answer
intermediate
Why is a user’s login session important in CSRF attacks?
Because CSRF exploits the fact that the user is already logged into a trusted site, so the site trusts requests coming from the user's browser without verifying if the user intended the action.
Click to reveal answer
beginner
Name one common method to prevent CSRF attacks.
Using CSRF tokens: unique, secret values included in forms or requests that the server checks to confirm the request is genuine and intended by the user.
Click to reveal answer
intermediate
What role does the 'SameSite' cookie attribute play in CSRF protection?
The 'SameSite' attribute restricts cookies from being sent with cross-site requests, reducing the risk that a malicious site can use the user's cookies to perform CSRF attacks.
Click to reveal answer
What does CSRF stand for?
ACross-site request forgery
BCross-site resource failure
CCross-server request function
DClient-side request form
✗ Incorrect
CSRF stands for Cross-site request forgery, a type of cyber attack.
Which of the following best describes a CSRF attack?
AAn attacker steals user passwords by phishing.
BAn attacker installs malware on the user’s device.
CAn attacker tricks a user’s browser to send unauthorized requests to a trusted site.
DAn attacker intercepts data between two servers.
✗ Incorrect
CSRF tricks the user's browser into sending unauthorized requests to a trusted site.
Which security measure helps prevent CSRF attacks?
AUsing strong passwords
BImplementing CSRF tokens
CDisabling JavaScript
DEncrypting data in transit
✗ Incorrect
CSRF tokens verify that requests are intentional and from the user.
Why does CSRF rely on the user being logged in to the target site?
ABecause logged-in users can change browser settings.
BBecause logged-in users have admin rights.
CBecause logged-in users can install software.
DBecause logged-in users have cookies that authenticate requests.
✗ Incorrect
CSRF exploits the authentication cookies sent by the browser when the user is logged in.
What does the 'SameSite' cookie attribute do to help prevent CSRF?
ABlocks cookies from being sent with cross-site requests.
BAllows cookies to be sent with all requests.
CEncrypts cookies on the server.
DDeletes cookies after each session.
✗ Incorrect
'SameSite' restricts cookies from being sent with cross-site requests, reducing CSRF risk.
Explain in your own words what a Cross-site request forgery (CSRF) attack is and why it is dangerous.
Think about how a trusted website can be tricked into doing something the user did not want.
You got /4 concepts.
Describe two common ways websites protect themselves against CSRF attacks.
Consider what websites check or restrict to confirm requests are genuine.
You got /3 concepts.
Practice
(1/5)
1. What is the main goal of a Cross-site request forgery (CSRF) attack?
easy
A. To encrypt user data for ransom
B. To steal a user's password by phishing
C. To overload a website with traffic causing it to crash
D. To trick a logged-in user into performing unwanted actions on a website
Solution
Step 1: Understand CSRF attack purpose
CSRF attacks aim to make a user unknowingly perform actions they did not intend on a trusted website.
Step 2: Compare with other attack types
Phishing steals passwords, DoS overloads servers, and ransomware encrypts data, which are different from CSRF.
Final Answer:
To trick a logged-in user into performing unwanted actions on a website -> Option D
Quick Check:
CSRF = trick user actions [OK]
Hint: CSRF tricks users into unwanted website actions [OK]
Common Mistakes:
Confusing CSRF with phishing attacks
Thinking CSRF steals passwords directly
Mixing CSRF with denial-of-service attacks
2. Which of the following is a common method to protect a website against CSRF attacks?
easy
A. Blocking all cookies from the browser
B. Encrypting all user passwords with SHA-1
C. Using secret tokens that must be submitted with requests
D. Disabling JavaScript on the website
Solution
Step 1: Identify CSRF protection techniques
Websites use secret tokens (CSRF tokens) that must be included in requests to verify they come from the user intentionally.
Step 2: Eliminate unrelated options
Encrypting passwords, blocking cookies, or disabling JavaScript do not specifically prevent CSRF attacks.
Final Answer:
Using secret tokens that must be submitted with requests -> Option C
Quick Check:
CSRF protection = secret tokens [OK]
Hint: CSRF defense uses secret tokens in requests [OK]
Common Mistakes:
Thinking password encryption stops CSRF
Believing blocking cookies prevents CSRF
Assuming disabling JavaScript is a CSRF fix
3. Consider this scenario: A user is logged into their bank website. An attacker sends a hidden form on another site that submits a money transfer request to the bank without the user's knowledge. Which security measure would stop this CSRF attack?
medium
A. The bank requires a unique CSRF token with each form submission
B. The bank uses HTTPS for all pages
C. The bank requires a strong password
D. The bank limits login attempts
Solution
Step 1: Analyze the attack method
The attacker tricks the user into submitting a form without their consent, typical of CSRF.
Step 2: Identify effective defense
Requiring a unique CSRF token ensures the form submission is legitimate and from the user, blocking forged requests.
Final Answer:
The bank requires a unique CSRF token with each form submission -> Option A
Quick Check:
CSRF blocked by unique tokens [OK]
Hint: Unique CSRF tokens stop forged form submissions [OK]
Common Mistakes:
Thinking HTTPS alone stops CSRF
Believing strong passwords prevent CSRF
Confusing login limits with CSRF defense
4. A developer wrote this code snippet to protect against CSRF:
Why might this code still be vulnerable to CSRF attacks?
medium
A. The form uses POST method instead of GET
B. The CSRF token is static and not unique per user session
C. The form does not include a CAPTCHA
D. The form action URL is relative
Solution
Step 1: Examine the CSRF token usage
The token value "12345" is hardcoded and does not change per user or session, making it predictable.
Step 2: Understand CSRF token requirements
Effective CSRF tokens must be unique and unpredictable per user session to prevent attackers from guessing them.
Final Answer:
The CSRF token is static and not unique per user session -> Option B
Quick Check:
Static tokens fail CSRF protection [OK]
Hint: CSRF tokens must be unique per session, not static [OK]
Common Mistakes:
Thinking POST method alone prevents CSRF
Assuming CAPTCHA is required for CSRF defense
Believing relative URLs cause CSRF vulnerabilities
5. A website uses cookies for user sessions but does not implement CSRF tokens. An attacker crafts a malicious link that triggers a fund transfer when clicked by a logged-in user. How can the website improve security to prevent this CSRF attack without removing cookies?
hard
A. Implement a unique CSRF token that must be submitted with sensitive requests
B. Switch all requests to use GET method instead of POST
C. Require users to re-enter their password on every page load
D. Disable cookies and use URL parameters for sessions
Solution
Step 1: Identify the vulnerability
Cookies alone do not prevent CSRF because browsers send them automatically with requests, allowing forged actions.
Step 2: Choose effective mitigation
Adding unique CSRF tokens ensures that only legitimate requests from the user are accepted, blocking forged requests.
Final Answer:
Implement a unique CSRF token that must be submitted with sensitive requests -> Option A
Quick Check:
Unique tokens prevent CSRF despite cookies [OK]
Hint: Add unique CSRF tokens to protect cookie-based sessions [OK]
Common Mistakes:
Thinking GET requests are safer than POST
Believing password re-entry on every page is practical