Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// cookies for a sub-domain.
cookieDomain = getCookieDomain(fnName, args);
if (cookieJar && typeof cookieJar.allowProgrammaticAccess === 'function' &&
!cookieJar.allowProgrammaticAccess(cookieDomain)) {
return self.host.dispatch(dispatchEvent, eventId,
`CookieStore: programmatic access to "${cookieDomain}" is denied`);
}
// serialize cookie object
if (fnName === COOKIE_STORE_PUT_METHOD && args[0]) {
args[0] = ToughCookie.fromJSON(args[0]);
}
if (fnName === COOKIE_STORE_UPDATE_METHOD && args[0] && args[1]) {
args[0] = ToughCookie.fromJSON(args[0]);
args[1] = ToughCookie.fromJSON(args[1]);
}
// add store method's callback argument
args.push(function (err, res) {
// serialize error message
if (err && err instanceof Error) {
err = err.message || String(err);
}
self.host.dispatch(dispatchEvent, eventId, err, res);
});
try {
cookieStore[fnName].apply(cookieStore, args);
}
catch (error) {
return callback(err, cookies.map(function (cookie) {
return Cookie.fromJSON(cookie); // serialize cookie object
}));
}
module.exports.cookieToString = function(cookie) {
// Cookie can either be a plain JS object or Cookie instance
if (!(cookie instanceof Cookie)) {
cookie = Cookie.fromJSON(cookie);
}
let str = cookie.toString();
// tough-cookie toString() doesn't put domain on all the time.
// This hack adds when tough-cookie won't
if (cookie.domain && cookie.hostOnly) {
str += '; Domain=' + cookie.domain;
}
return str;
};
// methods: putCookie, updateCookie, removeCookie, removeCookies,
// removeAllCookies
// or, onError
if (err || !cookies) {
return callback(err);
}
// methods: findCookies, getAllCookies
if (Array.isArray(cookies)) {
return callback(err, cookies.map(function (cookie) {
return Cookie.fromJSON(cookie); // serialize cookie object
}));
}
// method: findCookie
callback(err, Cookie.fromJSON(cookies));
});
serialize = function (cookie) {
if (!cookie) {
return;
}
return ToughCookie.fromJSON({
key: cookie.name || cookie.key,
value: cookie.value,
expires: cookie.expires,
maxAge: cookie.maxAge,
domain: cookie.domain,
path: cookie.path,
secure: cookie.secure,
httpOnly: cookie.httpOnly,
hostOnly: cookie.hostOnly,
extensions: cookie.extensions
});
},
asyncEach(cookies, function(cookieObject, next) {
const cookie = Cookie.fromJSON(cookieObject);
if (!cookie) {
return next();
}
storeJar.setCookie(cookie, getCookieUrl(cookie), next);
}, function(err) {
if (err) {
.map(function(cookie) {
return Cookie.fromJSON(cookie);
})
.filter(function(cookie) {
each(json.cookies, (function (c) {
this.jar.setCookie(
Cookie.fromJSON(c).toString(),
json.response.request.uri.href
);
}).bind(this));
}
this.values.forEach(x => jar.setCookie(Cookie.fromJSON(x), BASE_URL));
return jar;
login(sid) {
const cookie = Cookie.fromJSON({
key: 'connect.sid',
value: sid,
domain: 'repl.it',
path: '/'
})
return new Promise((resolve, reject) => {
this.jar.setCookie(cookie, 'https://repl.it/', (error) => {
if (error) return reject(error)
resolve()
})
})
}