Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redis-cookie-store

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-cookie-store - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

170

lib/redis-cookie-store.js

@@ -11,23 +11,25 @@ 'use strict';

function getKeyName(domain, path) {
if (path) {
return "cookie:" + domain + ":" + path;
} else {
return "cookie:" + domain;
}
}
function RedisCookieStore(redisClient) {
// putting id last to not break existing interface
function RedisCookieStore(redisClient, id) {
Store.call(this);
this.idx = {};
this.id = id || 'default';
this.client = redisClient;
this.synchronous = false;
}
util.inherits(RedisCookieStore, Store);
RedisCookieStore.prototype.synchronous = true;
RedisCookieStore.prototype.findCookie = function (domain, path, key, cb) {
return this.client.hget(getKeyName(domain, path), key, cb);
RedisCookieStore.prototype.getKeyName = function getKeyName(domain, path) {
if (path) {
return "cookie-store:" + this.id + ":cookie:" + domain + ":" + path;
} else {
return "cookie-store:" + this.id + ":cookie:" + domain;
}
};
RedisCookieStore.prototype.findCookies = function (domain, path, cb) {
RedisCookieStore.prototype.findCookie = function(domain, path, key, cb) {
return this.client.hget(this.getKeyName(domain, path), key, cb);
};
RedisCookieStore.prototype.findCookies = function(domain, path, cb) {
if (!domain) {

@@ -40,105 +42,59 @@ return cb(null, []);

var pathMatcher;
if (!path) {
// null or '/' means "all paths"
pathMatcher = function matchAll(domainKeys, cb) {
async.map(
domainKeys,
self.client.hgetall,
function (err, pathIndex) {
if (err) {
return cb(err);
}
var results = [];
for (var key in pathIndex) {
results.push(pathIndex[key]);
}
cb(null, results);
}
);
};
var paths = permutePath(path) || [path];
var pathMatcher = function matchRFC(domainKeys, cb) {
} else if (path === '/') {
pathMatcher = function matchSlash(domainKeys, cb) {
domainKeys.every(function (domainKey) {
if (domainKey.match(/cookie:.*:\/$/gi)) {
self.client.hgetall(
domainKey,
function (err, pathIndex) {
if (err) {
return cb(err);
}
var results = [];
for (var key in pathIndex) {
results.push(pathIndex[key]);
}
return cb(null, results);
}
);
return false;
}
return true;
});
};
var domainPrefix = domainKeys[0].match(/(.*cookie:[^:]*:)/i)[1]; //get domain key prefix e.g. "cookie:www.example.com"
var prefixedPaths = paths.map(function(path) {
return domainPrefix + path;
});
// console.log(prefixedPaths);
var keys = _.intersection(domainKeys, prefixedPaths).sort(function(a, b) {
return a.length - b.length;
});
} else {
var paths = permutePath(path) || [path];
pathMatcher = function matchRFC(domainKeys, cb) {
var domainPrefix = domainKeys[0].match(/(cookie:.*:)/i)[1]; //get domain key prefix e.g. "cookie:www.example.com"
paths = _.map(function (path) {
return domainPrefix + path;
});
var keys = _.intersection(domainKeys, paths);
async.parallel(keys.map(function(key) {
return function(callback) {
self.client.hgetall(key, function(err, hash) {
callback(err, hash);
});
};
}), function(err, results) {
if (err) {
return cb(err);
}
cb(null, _.merge.apply(_, results));
});
};
async.map(
keys,
self.client.hgetall,
function (err, pathIndex) {
if (err) {
return cb(err);
}
var results = [];
for (var key in pathIndex) {
results.push(pathIndex[key]);
}
return cb(null, results);
}
);
};
}
async.map(
domains,
function (curDomain, mapCallback) {
self.client.keys(getKeyName(domain) + ":*", function (err, domainKeys) {
async.parallel(domains.sort(function(a, b) {
return a.length - b.length;
}).map(function(domain) {
return function(callback) {
self.client.keys(self.getKeyName(domain) + ":*", function(err, domainKeys) {
if (err) {
return mapCallback(err);
return callback(err, null);
}
if (!domainKeys || !domainKeys.length) {
return mapCallback(null, null);
return callback(null, {});
}
pathMatcher(domainKeys, mapCallback);
pathMatcher(domainKeys, callback);
});
},
function (err, results) {
if (err) {
return cb(err);
};
}), function(err, results) {
if (err) {
return cb(err);
}
cb(err, _.values(_.merge.apply(_, results)).map(function(cookieString) {
var cookie = Cookie.parse(cookieString);
if (!cookie.domain) {
cookie.domain = domain;
}
results = _.chain(results)
.flatten()
.compact()
.map(function (c) {
var cookie = Cookie.parse(c);
cookie.domain = domain;
return cookie;
})
.value();
return cb(null, results);
}
);
return cookie;
}));
});
};
RedisCookieStore.prototype.putCookie = function (cookie, cb) {
this.client.hset(getKeyName(cookie.domain, cookie.path), cookie.key, cookie, cb);
RedisCookieStore.prototype.putCookie = function(cookie, cb) {
this.client.hset(this.getKeyName(cookie.domain, cookie.path), cookie.key, cookie, cb);
};

@@ -154,3 +110,3 @@

RedisCookieStore.prototype.removeCookie = function removeCookie(domain, path, key, cb) {
this.client.hdel(getKeyName(domain, path), key, cb);
this.client.hdel(this.getKeyName(domain, path), key, cb);
};

@@ -160,5 +116,5 @@

if (path) {
return this.client.del(getKeyName(domain, path), cb);
return this.client.del(this.getKeyName(domain, path), cb);
} else {
this.client.keys(getKeyName(domain) + ":*", function (err, keys) {
this.client.keys(this.getKeyName(domain) + ":*", function(err, keys) {
if (err) {

@@ -165,0 +121,0 @@ return cb(err);

{
"name": "redis-cookie-store",
"version": "0.0.1",
"version": "0.0.2",
"description": "Redis cookie store for tough-cookie module",

@@ -11,3 +11,3 @@ "main": "index.js",

"type": "git",
"url": "https://github.com/avovsya/redis-cookie-store.git"
"url": "https://github.com/benkroeger/redis-cookie-store.git"
},

@@ -24,11 +24,10 @@ "keywords": [

"bugs": {
"url": "https://github.com/avovsya/redis-cookie-store/issues"
"url": "https://github.com/benkroeger/redis-cookie-store/issues"
},
"homepage": "https://github.com/avovsya/redis-cookie-store",
"homepage": "https://github.com/benkroeger/redis-cookie-store",
"dependencies": {
"async": "^0.9.0",
"lodash": "^2.4.1",
"redis": "^0.10.3",
"tough-cookie": "^0.12.1"
"async": "1.5.0",
"lodash": "3.10.1",
"tough-cookie": "2.2.0"
}
}
# Redis Cookie Store
redis-cookie-store is a Redis cookie store for tough-cookie module. See
redis-cookie-store is a Redis store for tough-cookie module. See
[tough-cookie documentation](https://github.com/goinstant/tough-cookie#constructionstore--new-memorycookiestore-rejectpublicsuffixes) for more info.

@@ -12,3 +12,4 @@

`client` An existing redis client object you normally get from `redis.createClient()`
* `client` An existing redis client object you normally get from `redis.createClient()`
* `id` **optional** ID for each redis store so that we can use multiple stores with the same redis database [*default:* "default"]

@@ -22,3 +23,5 @@ ## Usage

var jar = new CookieJar(new RedisCookieStore(client));
var defaultJar = new CookieJar(new RedisCookieStore(client));
var myJar = new CookieJar(new RedisCookieStore(client, 'my-cookie-store'));

@@ -25,0 +28,0 @@ # License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc