Cookies
Alice authenticates with http://example.com
Server sends back a cookie:
ASPSESSID = akj32uad980wa4rlmaf9034
This is sent up with every request to example.com
Server looks at cookie, and uses that session
Cookies
The referer [sic] doesn't matter!
Where the request is going to is the important thing
Cookies
Cookies are NOT the problem
Trusting automatic behaviour is!
Protection
A separate authentication token for write requests
Protection
Alice authenticates with http://example.com
Server responds with cookie
ASPSESSID=l23j45093ifdpm34r0
Server stores in session
CSRF=klj45983uf0934nocn834
Server sends key down
<input type="hidden" name="CSRF" value="klj45983uf0934nocn834" />
Protection
Alice creates a user
Request is constructed:
URL: http://example.com/add-user
Data: user=jane&CSRF=klj45983uf0934nocn834
Cookie: ASPSESSID=l23j45093ifdpm34r0
Server opens the session, compares the CSRF token, sees it's good and does its thing
Protection
Bob tells Alice to go to http://dr-nefarious.com
Malicious site sends a request to
URL: http://example.com/add-user
Data: user=jane
Cookie: ASPSESSID=l23j45093ifdpm34r0
Server rejects the request
Hardening
Regenerate session every login
Avoid long-lasting logins
Regenerate CSRF tokens frequently