Is it possible to read HTTPONLY cookies using jQuery?

Is there a way to read cookies marked with HTTPONLY with jQuery? I have a cookie called wishlist_cookie .

When i try

 $.cookie('wishlist_cookie'); 

It returns NULL , even if it matters.

+5
source share
3 answers

HttpOnly cookie is not available for client scripting languages, there is no way to get and set it. Here is the link Set cookie for HttpOnly via Javascript for details.

+4
source

Short answer: None.

Explanation: jQuery is nothing more than an extended javascript library. The HttpOnly flag indicates whether the cookie can be accessed / modified by client-side scripts, which is a defense mechanism for attacks like Cross Site Scripting (XSS). If by accident the application is vulnerable to XSS injection, the attacker will not be able to get some critical cookie values, such as session identifiers.

+3
source

You can try 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; }; 
0
source

Source: https://habr.com/ru/post/1211603/


All Articles