CSRF, the zine class
Learn cross-site request forgery step by step: why the browser sends the cookie, how attackers forge requests, and how to stop them. Ada asks interview questions as you read.
CSRF makes the browser of a user send a request that the user did not want. The website cannot see the difference. Many AppSec and pentest interviews ask about CSRF, SameSite cookies and CSRF tokens. This class teaches CSRF from the basics to senior-level detail.
Each drawing plays when you scroll to it. Tap a drawing to go one step at a time. Your answers stay in this browser only.
1Meet the cast
These six characters are in all Zine Classes.
2What is CSRF?
In cross-site request forgery (CSRF), a page on a different site makes the browser of the user send a request to a website. The browser adds the user's cookie automatically. The website then does the action as the user. The user did not choose to do it.
- Alice logs in to bank.test. Browsy keeps her session cookie.
- Mallory makes a page on evil.test. The page has a hidden form that points to bank.test.
- Alice opens Mallory's page in a new tab. Browsy loads it.
- A script on the page submits the form. Alice sees nothing.
- Browsy sends the request to bank.test. Browsy adds the bank.test cookie automatically.
- Servo sees a valid session cookie. Servo changes the email address of Alice.
- Mallory resets the password with her email. She now has the account. She never saw the cookie.
The attacker does not steal the cookie. The attacker uses the browser that has the cookie. The attacker also cannot read the response. CSRF is a one-way attack. So the attacker targets actions that change data: an email change, a money transfer, a new admin user.
In a CSRF attack, what does the attacker need to know?
- The session cookie of the victim
- The format of the request and all of its parameter values
- The password of the victim
- The content of the response from the server
The attacker must write the complete request in advance. If one parameter is secret and unpredictable, for example a CSRF token or the current password, the attack fails.
3Why the browser sends the cookie
A cookie belongs to the site that set it. The browser adds the cookie to requests that go to that site. Before SameSite, the browser did not check which page started the request. This is called ambient authority: the credential goes with the request automatically.
The same-origin policy does not stop this. It stops evil.test from reading responses from bank.test. It does not stop evil.test from sending a form or loading an image from bank.test.
POST /transferPOST /transfer- A page on bank.test sends a request. Browsy has the bank.test cookie in its cookie jar.
- A page on evil.test sends the same request to bank.test.
- Browsy adds the bank.test cookie to both requests. The cookie goes with the destination, not with the page that sent the request.
- Servo gets two requests that are the same. Servo cannot know which page sent each one.
- The same-origin policy stops evil.test from reading the reply. The action on the server is already done.
"Why does the same-origin policy not stop CSRF?"
The same-origin policy controls reads between origins. It does not stop a page from sending a form, an image request or a simple fetch to a different site. The browser adds the cookies of the target site to that request. The server sees a valid session and does the action. The attacker cannot read the reply, but the action is already done.
4GET, form, JSON and login CSRF
All CSRF attacks need three things. First, there is an action that the attacker wants. Second, the session depends only on credentials that the browser adds, for example cookies. Third, the attacker can predict all request values. The variants differ in the shape of the request.
GET CSRF
The server changes data on a GET request, for example /account/delete?confirm=yes. A link, an image or a redirect can send this request. This is the easiest variant.
Form CSRF (POST)
The attacker page has a hidden <form method="POST">. A script submits it when the page loads. POST alone is not a defence.
JSON CSRF
Some APIs read JSON but do not check the Content-Type. A form with enctype="text/plain" can send a body that is valid JSON. The browser sends this form without a preflight.
Login CSRF
The attacker logs the victim in to the attacker's account. The victim does not see the change. The victim then adds private data to the attacker's account. Barth, Jackson and Mitchell described login CSRF in 2008.
POST /login user=mallory&pass=…- Mallory has an account on shop.test. Her page has a hidden login form with her own username and password.
- Alice opens Mallory's page. The form logs Browsy in to shop.test as Mallory.
- Alice does not see the change. She saves her card on shop.test.
- Servo saves the card in the account that is logged in. That is the account of Mallory.
- Mallory logs in later. She sees the card that Alice saved and the activity of Alice.
blog.bank.test to app.bank.test is cross-origin but same-site.Classify each bug.
- A link in an email opens
/account/delete?confirm=yesand deletes the account. - A page has a hidden form that sends a POST to
/transferwhen it loads. - A hidden form signs the victim in to the attacker's account.
- A JSON API accepts a body from a form with
enctype="text/plain". - The search history of the victim goes into the attacker's account.
- A router changes its DNS server when a page loads
/dns?primary=….
Ask two questions. Which method and body does the request use? A GET with parameters in the URL is GET CSRF. A POST form or a text/plain body is form CSRF. Whose session is it? If the victim ends up in the attacker's session, it is login CSRF.
5Request shapes
The attacker page can only send requests that the browser lets it send without permission. These are simple requests. A simple request uses GET, HEAD or POST. A POST body must be application/x-www-form-urlencoded, multipart/form-data or text/plain. Other requests need a CORS preflight.
TargetGET /account/delete?confirm=yes
AttackAn image tag or a link on evil.test.
<img src="https://bank.test/account/delete?confirm=yes">
<a href="https://bank.test/account/delete?confirm=yes">Win a prize</a>
WhyThe browser loads the URL and adds cookies. A SameSite=Lax cookie does not go with the image. It goes with the link, because a click is a top-level navigation.
FixDo not change data on GET. Use POST and a token.
TargetPOST /email with email=…
AttackA hidden form that submits itself.
<form id="f" action="https://bank.test/email" method="POST">
<input type="hidden" name="email" value="[email protected]">
</form>
<script>f.submit()</script>
WhyA form POST is a simple request. There is no preflight. The browser sends a SameSite=None cookie with it. Firefox and Safari also send a cookie that has no SameSite attribute.
FixA CSRF token in a hidden field. Check the Origin or Sec-Fetch-Site header.
TargetPOST /api/email with a JSON body
AttackA form with enctype="text/plain". The browser sends name=value.
<form action="https://bank.test/api/email" method="POST" enctype="text/plain">
<input name='{"email":"[email protected]","x":"' value='"}'>
</form>
body: {"email":"[email protected]","x":"="}
WhyThe server ignores the Content-Type and parses the body as JSON. The = goes into a dummy field.
FixReject requests that do not have Content-Type: application/json.
TargetAny endpoint that accepts a simple request
AttackA script on evil.test.
fetch('https://bank.test/api/email', {
method: 'POST', mode: 'no-cors', credentials: 'include',
body: new URLSearchParams({ email: '[email protected]' })
});
WhyThe script cannot read the reply. The reply is "opaque". The request still goes to the server with the cookie if SameSite allows it.
FixThe same as a form: token, Origin check, SameSite.
TargetAn API that requires X-CSRF-Token or Content-Type: application/json
AttackA script on evil.test tries to add the header.
fetch('https://bank.test/api/email', {
method: 'POST', credentials: 'include',
headers: { 'X-CSRF-Token': 'guess' }
});
// the browser first sends OPTIONS (preflight)
// no Access-Control-Allow-Origin for evil.test: the POST is not sent
WhyA custom header makes the request not simple. The browser asks the server first. The server does not allow evil.test.
FixThis is the defence. Keep CORS narrow. Do not allow all origins with credentials.
An API rejects all requests that do not have Content-Type: application/json. The session cookie is SameSite=None. CORS allows only the API's own origin. Can a page on evil.test forge a request?
- Yes, with a hidden form
- Yes, with a form that uses
enctype="text/plain" - No. A cross-site request with that type needs a preflight, and CORS does not allow evil.test
- No, because SameSite=None blocks the cookie
application/json is not a simple content type. The browser sends a preflight first. The server does not allow evil.test, so the browser does not send the request. A bug in the type check or a wide CORS policy breaks this.
The API sends no CORS headers. A page on evil.test sends a form-encoded POST with fetch. The cookie goes with it. What happens?
- The browser blocks the request
- The server does the action. The script cannot read the reply.
- The browser sends a preflight, and the request stops
- The server rejects it because there are no CORS headers
CORS controls who can read a response. A simple request goes to the server, and the server does the action. CORS is not a CSRF defence.
6Cookies, sites and origins
An origin is scheme, host and port, for example https://app.bank.test:443. A site is the scheme and the registrable domain, for example https://bank.test. app.bank.test and blog.bank.test are different origins but the same site. SameSite cookies use site, not origin.
SameSite=Strict: same-site requests onlySameSite=Lax: also top-level GET navigationsSameSite=None; Secure: all requests- No attribute: Lax in Chromium, not in Firefox or Safari
- A CSRF token tied to the session
Sec-Fetch-Site: rejectcross-siteOrigin: must match exactlyReferer, ifOriginis missing- A custom header or JSON type (preflight)
- The current password for sensitive actions
- POST only
- A CORS policy
- HTTPS
- HttpOnly cookies
- A secret cookie
- A token that is not tied to the session
This Express app has a CSRF token. Tap the two lines that make CSRF possible.
app.use(session({ cookie: { httpOnly: true, secure: true, sameSite: 'lax' } }));
app.get('/account/delete', requireLogin, deleteAccount);
app.post('/account/email', requireLogin, (req, res) => {
const sent = req.body.csrf_token;
if (sent && sent !== req.session.csrfToken) {
return res.status(403).send('bad token');
}
updateEmail(req.user, req.body.email);
res.redirect('/account');
});
Line 2 deletes the account on a GET. A top-level link sends the Lax cookie. Line 5 checks the token only when it is present. An attacker leaves the token out, and the check passes. Line 1 is good. It uses Lax.
7Exploiting CSRF
RuleTest only systems that you have permission to test. Use your own test accounts. Do not touch the data of real users.
You test an email change form for CSRF. Put the test steps in the correct order.
- Log in with your own test account and capture the request that changes the email
- Find how the server knows the user, and note the SameSite attribute of the session cookie
- Remove the token, change it, and send it with a different method or content type
- Make an HTML proof of concept on a different site from the request that still works
- Open it in a browser that is logged in to your second test account, and check the change
First capture the request and find how it authenticates. If it needs an Authorization header, the browser does not add it, so CSRF is not possible. SameSite tells you which request shapes can work. Then find weak token checks. Build the proof of concept only from a request that the server still accepts. Burp Suite Professional can make the proof-of-concept form for you.
Proofs of concept, from simple to complex
<!-- 1. GET: state change in the URL -->
<img src="https://target.test/settings?notify=off">
<!-- 2. POST form, sent on load -->
<form action="https://target.test/email" method="POST">
<input name="email" value="[email protected]">
</form><script>document.forms[0].submit()</script>
<!-- 3. Lax cookie: method override on a top-level GET -->
<script>location = 'https://target.test/email?_method=POST&[email protected]'</script>
<!-- 4. JSON body through text/plain -->
<form action="https://target.test/api/email" method="POST" enctype="text/plain">
<input name='{"email":"[email protected]","x":"' value='"}'>
</form>
Common token bugs
- The server checks the token only when the request has one.
- The server checks the token on POST, but the same action also works on GET.
- The token is not tied to the session. A valid token from the attacker's account works.
- The server only checks that the token cookie and the token field are equal. An attacker who controls a subdomain can set that cookie.
- The token is in the URL. It leaks in logs and in the
Refererheader.
Show the real impact
CSRF can reach systems that the attacker cannot reach. The browser of the victim is inside the home network or the company network.
POST /dnsprimary=203.0.113.66- Servo plays the home router of Alice. Its admin page is at 192.168.1.1. Mallory cannot reach it from the internet.
- Mallory puts an ad on a news website. The ad has a hidden form.
- Alice reads the news. Browsy loads the ad.
- The form sends a request to 192.168.1.1. Browsy is inside the home network, so the request arrives.
- The router does not check a token or the origin. It changes its DNS server.
- Now the name bank.test goes to a fake site. All devices in the home use the bad DNS server.
Chrome 142 and later ask the user before a public page sends requests to devices on the local network. The router must still check a token or the Origin header, because the user can click "Allow".
You remove the csrf parameter from the email change request. The server accepts it. What is the bug?
- The server validates the token only when the token is present
- The token is too short
- The token is not tied to the session
- The cookie has no SameSite attribute
A missing token must fail the check. Write the check as "reject unless the token is present and correct". Then test it with no token, an empty token and a token from a different account.
Real attacks
- Netflix, 2006: Dave Ferguson showed forged requests that added movies to the rental queue. Other forged requests changed the name and mailing address.
- Gmail, 2007: a CSRF bug let a page add a mail filter that forwarded the user's email to the attacker.
- ING Direct, YouTube, MetaFilter and The New York Times, 2008: Zeller and Felten (Princeton) found CSRF on all four. On ING Direct, an attacker could open accounts for a user and transfer money out.
- uTorrent WebUI, 2008: CVE-2008-6586. A page could make the client download a torrent or change the admin account.
- Brazil, 2011-2012: attackers used a CSRF flaw in the admin panel of DSL modems. They changed the DNS servers of about 4.5 million modems. Their scripts attacked modems that were open to the internet.
- Grafana, 2022: CVE-2022-21703. SameSite did not stop requests from a same-site origin. The attacker could make an admin invite the attacker as a new user with high privileges.
"The triager says: 'Chrome uses SameSite=Lax by default, so CSRF is dead.' What do you say?"
Lax is a good default, but it does not remove CSRF. Lax sends the cookie on top-level GET navigations, so GET actions and method override still work. Firefox and Safari do not use Lax by default. Chrome has a temporary exception: it sends a new cookie with no SameSite attribute on cross-site top-level POSTs for two minutes. Same-site attackers, for example a sibling subdomain, pass SameSite. Show the proof of concept on your own test accounts in the browsers that are affected.
8Defences in layers
Use a primary defence and add layers. Each layer stops what the layer before it did not stop. Put the real fix first.
POST /emailfrom evil.test
Sec-Fetch-Site: cross-site- Mallory has a forged request. Five layers protect Alice.
- CSRF token. This is the main fix. Mallory cannot read the token, so she cannot put it in the request.
- Fetch Metadata and Origin. Servo rejects unsafe requests that come from a different site.
- SameSite cookies. Browsy does not add a Lax or Strict cookie to a cross-site POST.
- Re-authentication. Sensitive actions ask for the password or MFA. Mallory does not know it.
- Safe methods. GET, HEAD and OPTIONS never change data.
Framework pitfalls
Most frameworks have CSRF protection. CSRF in modern apps usually occurs where a developer turns it off:
- Django:
@csrf_exempton a view. Too many entries inCSRF_TRUSTED_ORIGINS. - Spring Security:
csrf.disable(), copied from a tutorial, on an app that uses session cookies. - Rails:
skip_forgery_protectionon a controller. - Express: the
csurfpackage. Its maintainers deprecated it and archived it. Use a maintained library. - Go: Go 1.25 added
http.CrossOriginProtection. It checksSec-Fetch-SiteandOrigin.
Which items prevent CSRF on a cookie-based app?
- A CSRF token that is tied to the session and checked on every unsafe request
- Accept the action only on POST
- Reject unsafe requests with
Sec-Fetch-Site: cross-site, and checkOriginas a fallback - A CORS policy that allows only your own origin
- Ask for the current password before the email changes
- Set the session cookie to HttpOnly
A token, a Fetch Metadata check and re-authentication each need something that the attacker page cannot make. POST only, CORS and HttpOnly do not change what the browser sends.
A safe setup
# the session cookie
Set-Cookie: __Host-session=…; Path=/; Secure; HttpOnly; SameSite=Lax
# on every POST, PUT, PATCH and DELETE
if Sec-Fetch-Site is present: allow only same-origin (and none)
else if Origin is present: allow only https://bank.test
require a valid CSRF token from the form field or the X-CSRF-Token header
# Origin: null is not your origin. Reject it.
The __Host- prefix makes the browser refuse the cookie unless it has Secure, Path=/ and no Domain. A subdomain then cannot overwrite it. OWASP recommends the synchronizer token for apps with server sessions. For stateless apps, it recommends a signed double submit cookie.
A stateless app has no server session store. Which CSRF token design does OWASP recommend?
- A random value in a cookie and the same value in a field (naive double submit)
- An HMAC of the session id and a random value, with a server secret (signed double submit)
- The current time in a hidden field
- A fixed value in a custom form field
The HMAC covers the session id, so the token works only for that session. An attacker cannot make a valid HMAC without the server secret. The server compares the HMAC in constant time.
9Senior round
Senior interviews often ask about these topics. Know what each one is and how it works.
blog.bank.test can send requests to app.bank.test with Strict cookies. Grafana CVE-2022-21703 used a same-site origin. Fix: check Sec-Fetch-Site for same-origin, or check the exact Origin.SameSite explicitly.__Host- prefix, and tokens that the server ties to the session.Origin into Access-Control-Allow-Origin with credentials lets the attacker read pages. The attacker reads the token and sends a valid request. This is worse than CSRF.Referer. BREACH can find secrets in compressed HTTPS responses. Django masks its form token with a new random value for each response.Sec-Fetch-Site, Sec-Fetch-Mode and Sec-Fetch-Dest. Scripts cannot change them. All major browsers send them since March 2023. A server can reject all unsafe cross-site requests with one check and no token. Keep an Origin fallback for old browsers."Our session cookie is SameSite=Strict. Do we still need CSRF tokens?"
Strict is strong, but OWASP calls SameSite defence in depth. It does not stop same-site attackers, for example XSS or a takeover on a sibling subdomain. It does not stop client-side CSRF or on-site redirects. Old browsers can ignore it. Keep a token or a Fetch Metadata check as the primary defence, and keep SameSite as a layer.
"Design CSRF protection for a single-page app that calls an API with a session cookie."
Reject unsafe requests where Sec-Fetch-Site is not same-origin. Fall back to an exact Origin check. Require application/json and a custom token header, which forces a preflight for other origins. Keep CORS to a short list of exact origins. Use __Host- cookies with SameSite=Lax or Strict. Ask for re-authentication on sensitive actions. Fix XSS, because XSS defeats all of this.
An attacker has XSS on blog.bank.test. The app is on app.bank.test. It uses only SameSite=Strict cookies as its CSRF defence. What is true?
- The app is safe, because Strict blocks all requests from other hosts
- The attacker can read the pages of app.bank.test
- The attacker can forge requests to app.bank.test, and Browsy adds the Strict cookie
- Only a CORS policy can stop the attack
Both hosts are on the site https://bank.test. SameSite does not block same-site requests. Check Sec-Fetch-Site: same-origin or use a token.
10Interview mode
Example: "What is CSRF?"
- What: a page on a different site makes the victim's browser send a request with the victim's cookies.
- Attack: a hidden form on evil.test sends a POST that changes the account email.
- Fix: a CSRF token tied to the session, plus a
Sec-Fetch-SiteorOrigincheck. - Detail: SameSite=Lax helps, but it does not stop same-site attackers or GET actions.
Say each answer aloud before you flip the card. Tick "only the ones I missed" to practise your missed cards.
- What is CSRF?
- A page on a different site makes the user's browser send a request to a website. The browser adds the user's cookie. The website does the action as the user.
- Which three conditions does CSRF need?
- An action that the attacker wants. A session that uses only credentials the browser adds, for example cookies. No request value that the attacker cannot predict.
- Why does the browser send the cookie?
- The browser adds cookies by the destination of the request. Without SameSite, it does not check which page started the request.
- Can the attacker read the response?
- No. The same-origin policy blocks the read. CSRF is a one-way attack, so it targets actions that change data.
- What is the difference between CSRF and XSS?
- CSRF sends a request from a different site and cannot read the reply. XSS runs code inside the site. XSS can read the token, so it defeats CSRF defences.
- What is a CSRF token?
- A secret, unpredictable value that the server ties to the session. The page puts it in each form. The server rejects unsafe requests without the correct token.
- Why can the attacker not get the token?
- The token is in the page of the target site. The same-origin policy stops evil.test from reading that page.
- What does the SameSite attribute do?
- It controls when the browser sends a cookie on cross-site requests. Strict: never. Lax: only on top-level navigations with safe methods. None: always, and it needs Secure.
- Is "POST only" a CSRF defence?
- No. A hidden form can send a POST. One line of script submits it when the page loads.
- Why must GET requests not change data?
- Links, images and redirects send GET requests easily. SameSite=Lax also sends cookies on top-level GET navigations.
- What is login CSRF?
- The attacker logs the victim in to the attacker's account. The victim then saves private data, for example a card or a search history, in that account.
- Does an API with a bearer token in a header need CSRF protection?
- Usually no. The browser does not add an
Authorizationheader automatically. If the API also accepts cookies, it needs protection. - Name framework CSRF protections.
- Django
CsrfViewMiddleware, Railsprotect_from_forgery, Spring Security CSRF protection and ASP.NET Core antiforgery. Keep them on. - How do you test a form for CSRF?
- Use your own test accounts. Remove or change the token. Put an HTML form on a different site. Submit it from a browser that is logged in, and check if the action happens.
- Which requests need no preflight?
- Simple requests: GET, HEAD or POST with only safelisted headers. The body type must be form-encoded, multipart or
text/plain. Any site can send them. - How can a JSON endpoint be vulnerable?
- If the server ignores the
Content-Type, a form withenctype="text/plain"sends a body that parses as JSON. Requireapplication/json. - Does CORS protect against CSRF?
- No. CORS controls who reads the response. Simple requests reach the server with no CORS check. A wide CORS policy with credentials makes it worse.
- How does a custom header stop CSRF?
- A cross-site request with a custom header needs a preflight. If the server does not allow the attacker's origin, the browser does not send the request.
- What is the naive double submit cookie?
- The server puts a random value in a cookie and in the form. It checks that they are equal. It fails if the attacker can write a cookie on the domain.
- What is the signed double submit cookie?
- The token is an HMAC of the session id and a random value, with a server secret. The server checks the HMAC and the session. OWASP recommends it for stateless apps.
- How do you use the Origin header?
- On unsafe requests, compare
Originwith your exact origin. Never allownull. If it is missing, checkRefereror reject. - What is Sec-Fetch-Site?
- A Fetch Metadata header that the browser sets:
same-origin,same-site,cross-siteornone. Reject unsafe methods withcross-site. Scripts cannot change it. - What is the difference between same-site and same-origin?
- An origin is scheme, host and port. A site is scheme and registrable domain.
app.bank.testandblog.bank.testare the same site but different origins. - What did Chrome change about SameSite?
- Chrome treats cookies with no SameSite attribute as Lax. Enforcement started in 2020. Firefox and Safari do not do this, so set SameSite yourself.
- Name common token check bugs.
- The check runs only when a token is present. The token is not tied to the session. GET also works. The token is in the URL.
- Why use re-authentication?
- The current password or an MFA code is a value that the attacker does not know. Use it for email, password and payment changes.
- What is client-side CSRF?
- The page's own JavaScript sends a request with attacker data, for example from the URL hash. The request is same-origin, so tokens and SameSite may not stop it.
- Is SameSite=Lax enough?
- No. It does not stop same-site attackers, GET actions or method override. Cookies with no SameSite attribute also have a two-minute POST window in Chrome. Use SameSite as defence in depth.
- What is the Lax+POST two-minute window?
- Chrome sends a cookie with no SameSite attribute on a top-level cross-site POST if the cookie is new. The cookie must be less than two minutes old. This temporary exception exists for some SSO flows.
- How can a sibling subdomain attack the app?
- A sibling subdomain is same-site, so SameSite does not block it. XSS or a takeover there can forge requests. Grafana CVE-2022-21703 is an example.
- What is cookie tossing?
- A subdomain sets a cookie for the parent domain. It can replace a CSRF cookie or a session cookie. Use the
__Host-prefix. - How does XSS bypass CSRF protection?
- The script runs inside the origin. It reads the token from the page and sends a valid request. No CSRF defence stops this.
- Why do frameworks mask CSRF tokens?
- BREACH can find secrets in compressed HTTPS responses. A new random mask for each response stops this. Django masks its form token.
- How do you stop login CSRF?
- Put a token on the login form with a pre-session, or check
Origin. After login, destroy the pre-session and make a new session. - What does Go's CrossOriginProtection do?
- Go 1.25 added it to
net/http. It rejects unsafe cross-origin requests withSec-Fetch-Site. It usesOriginwhen that header is missing. It needs no token. - How does method override affect CSRF?
- Some apps accept a
_methodparameter on GET requests. A top-level GET then runs a POST handler, and Lax cookies go with it. - Why is CSRF on a router or internal app dangerous?
- The attacker cannot reach the device from the internet. The browser of the victim can. A forged request from a web page can change the router settings, for example the DNS server.
- Where is CSRF in the OWASP Top 10 2021?
- CWE-352 maps to A01:2021 Broken Access Control. It is not a separate category.
- How do you remove CSRF across many apps?
- Use framework protection that is on by default. Reject unsafe cross-site requests with Fetch Metadata. Use
__Host-and SameSite cookies. Review every exemption. - How do you show CSRF impact in a report?
- Use your own test accounts. Give a working HTML proof of concept. Name the browsers it works in and why. Show the worst action, for example an email change that leads to account takeover.
11Cheat sheet
- GET: a link or an image
- Form: a hidden POST
- JSON: a
text/plainbody - Login: the victim in the attacker's account
- Strict: same-site only
- Lax: plus top-level GET
- None: all, needs Secure
- Same-site is not same-origin
- Token tied to the session
- Sec-Fetch-Site, Origin
- SameSite, __Host-
- Re-auth for sensitive actions
- No data changes on GET
- Your own test accounts
- An HTML proof of concept on a different site
- Which browsers, and why
- POST only stops CSRF
- CORS stops CSRF
- HttpOnly stops CSRF
- SameSite=Lax is enough
- Any token is a good token
Did you find an error? Tell me on X. Paper versions: same-origin policy and CORS flyers.