Lecture 13: Cookies, Session Management, and CSRF

Intro to Cookies


Why do we need cookies to maintain state across multiple HTTP requests?




Viewing Cookies


What stateful information might the cookies on cnn.com be storing in cookies?





Why do we need to define domain and path scopes for each cookie, instead of sending every cookie in the browser on every request?








Why might we want to let mail.google.com set a cookie for google.com?




Scope for Sending Cookies





If Cookie 1’s path was changed to /user, which of the three domains would it be sent to?




Examples of Setting and Sending Cookies




Modifying Cookies in Browser


See Q3.5-Q3.9 on Homework 6 for some practice on viewing and modifying cookies in your browser.







Bypassing Same-Origin Policy with Cookies


What difference between the same-origin policy and cookie policy causes this vulnerability?

(Fill in the blanks: Same-origin policy thinks that financial.example.com and blog.example.com are controlled by ___ (the same/different) organization(s) because ___, but cookie policy thinks they are controlled by ___ (the same/different) organization(s) because ___.)




Session Management with HTTP Auth




Session Token Analogy




Session Tokens




Storing Session Tokens


When could a man-in-the-middle attacker on the network steal a user’s session token?




Cross-Site Request Forgery (CSRF)

HTML Forms


Why do we prefer sending HTML forms using HTTP POST requests instead of GET requests?




Session Management with Cookies




Cross-Site Request Forgery (CSRF)


Fill in the blanks with (attacker/victim/server) or (GET/POST): In a CSRF attack, the ___ sends an HTTP ___ request to the ___. The ___ responds with some HTML that fills out a form with malicious input and some Javascript that sends the form to the ___. The ___ sends the filled-out form to the ___ as an HTTP ___ request, along with any browser cookies. The ___ thinks this request is legitimate and accepts the malicious form input.




Real-World CSRF Attacks




Defense: CSRF Tokens



Would the CSRF token defense work if the server used the same CSRF token for every request, regardless of user?




Defense: Referer Validation


Would referer validation stop the CSRF attack shown at the beginning of the video? Assume the browser attaches the correct referer, and the referer field is not blank.




CSRF Conclusion