Web Security - Lecture 03 - Session Attacks
Understanding what happened here.
This is CS253 https://web.stanford.edu/class/cs253
Doing document.cookie Output will be `` [no cookie]. Because the cookie we set on 106a WILL NOT be sent while loading the page, the path was set to Path='/class/cs106a' and the page we are loading has a different path.
Now we create an iframe linking to cs106a
const iframe = document.createElement('iframe')
iframe.src='https://web.stanford.edu/class/cs106a'
document.body.append(iframe)
NOW! the cookie we set on 106a WILL be sent while loading the iframe because, the path was set to Path='/class/cs106a' and the we are loading the iframe of same path.
Also NOTE! Another reason why the cookie will be sent is because the Site is same, so the Same Site Cookie policies are not interfering.
Now we can use this to pull the Cookies form the iframe document:
iframe.contentDocument.cookie
NOW! this worked because of SOP, as the Origins are same [The web page link and the iFrame source] so the browser allowed the page to access the Document and pull out the cookies from the embedded iFrame.
This is CS106a https://web.stanford.edu/class/cs106a
document.cookie= 'session=1234; Path=/class/cs106a'.Path='/class/cs106a' for scoping the cookie only to that particular class.document.cookie Output will be session=1234.