Issue with cookies handling

157 views
Skip to first unread message

Leandro Azevedo

unread,
Aug 23, 2016, 4:08:49 PM8/23/16
to jsdom
Hi everyone,

I'm trying to store cookies from a website and load/save them on each visit.

For regular cookies, I could use window.document.cookie

But some wesbites store HTTP-only cookies.

From Wikipedia:
An HttpOnly cookie cannot be accessed by client-side APIs, such as JavaScript. This restriction eliminates the threat of cookie theft via cross-site scripting (XSS). However, the cookie remains vulnerable to cross-site tracing (XST) and cross-site request forgery (XSRF) attacks. A cookie is given this characteristic by adding the HttpOnly flag to the cookie.

The cookieJar used by jsdom is tough to handle.
The cookieJar CAN get http-only cookies but the tough-cookie object methods can't be accessed as I posted before.

Does anybody knows a way to get all the cookies from jsdom?

Many thanks!

Leandro Azevedo

unread,
Aug 23, 2016, 8:45:33 PM8/23/16
to jsdom

Well I tried and tried it. I just can't get the cookie data or access them.

I can only see it if I use console.log, otherwise it is unnaccessible.


var jsdom = require("jsdom"); var cJar = jsdom.createCookieJar(); var mycookie = 'LastVisit=1471990051; domain=google.com; path=/; hostOnly=true; creation=2016-08-23T22:08:19.867Z; lastAccessed=2016-08-23T22:08:19.867Z'; jsdom.env({ userAgent: 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0', url: 'http://www.google.com', cookieJar: cJar, cookie: mycookie, done: function (err, window){ //console.log( cJar.getCookies() ); /* ERROR: jsdom\node_modules\tough-cookie\lib\cookie.js:1026 var secure = options.secure; ^ */ console.log(cJar); // although it shows the cookie I cannot read any of it. only works with console.log() } });

Reply all
Reply to author
Forward
0 new messages