Is there any way of reading cookies marked with HTTPONLY checked, with jQuery? I have a cookie named wishlist_cookie
.
When I try
$.cookie('wishlist_cookie');
It returns NULL
even if it has a value.
Is there any way of reading cookies marked with HTTPONLY checked, with jQuery? I have a cookie named wishlist_cookie
.
When I try
$.cookie('wishlist_cookie');
It returns NULL
even if it has a value.
HttpOnly cookie is not available to client-side scripting languages, there is no way to get and set it. Here is the link Set a cookie to HttpOnly via Javascript for details.
Short Answer: No.
Explanation: jQuery is nothing but an extended library of javascript. The HttpOnly flag tells if the cookie can be accessed/altered by the client side scripts which is a defensive mechanism for Cross Site Scripting (XSS) attacks. If by any chance the application is vulnerable to XSS injections, the attacker will not be able to get some critical cookie values like session ids.
You can try in this way
var currentSession = [];
var session = function readCookie() {
match = document.cookie.match(new RegExp('TestCookie' + '=([^;]+)'));
if (match) {
var array = match[1].split('&');
for (var i = 0; i < array.length; i++) {
name = array[i].split('=')[0];
value = array[i].split('=')[1];
currentSession.push(setCokiesValue(name, value));
}
}
return currentSession;
};