From c4f6159bfb0f796e77f479fc76508918fae6d052 Mon Sep 17 00:00:00 2001 From: smcmurray Date: Sat, 19 May 2018 18:31:27 -0700 Subject: [PATCH 1/2] Allow maxAge of 0. Eliminate unneeded work when missing signing keys 0 is a legitimate value for maxAge. If there are no signing keys, you can abort sooner. There's no need to parse the signature cookie, etc. if you already know you will fail. --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3672dfc..22488b6 100644 --- a/index.js +++ b/index.js @@ -65,11 +65,12 @@ Cookies.prototype.get = function(name, opts) { value = match[1] if (!opts || !signed) return value + if (!this.keys) throw new Error('.keys required for signed cookies'); + remote = this.get(sigName) if (!remote) return data = name + "=" + value - if (!this.keys) throw new Error('.keys required for signed cookies'); index = this.keys.index(data, remote) if (index < 0) { @@ -162,7 +163,7 @@ Cookie.prototype.toString = function() { Cookie.prototype.toHeader = function() { var header = this.toString() - if (this.maxAge) this.expires = new Date(Date.now() + this.maxAge); + if (this.maxAge || 0 === this.maxAge) this.expires = new Date(Date.now() + this.maxAge); if (this.path ) header += "; path=" + this.path if (this.expires ) header += "; expires=" + this.expires.toUTCString() From acd754888dd7640dc6ddea0cdd4f8bbb1654df15 Mon Sep 17 00:00:00 2001 From: smcmurray Date: Sat, 19 May 2018 19:40:58 -0700 Subject: [PATCH 2/2] Removed maxAge PR --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 22488b6..b4587f3 100644 --- a/index.js +++ b/index.js @@ -65,8 +65,8 @@ Cookies.prototype.get = function(name, opts) { value = match[1] if (!opts || !signed) return value - if (!this.keys) throw new Error('.keys required for signed cookies'); - + if (!this.keys) throw new Error('.keys required for signed cookies') + remote = this.get(sigName) if (!remote) return @@ -163,7 +163,7 @@ Cookie.prototype.toString = function() { Cookie.prototype.toHeader = function() { var header = this.toString() - if (this.maxAge || 0 === this.maxAge) this.expires = new Date(Date.now() + this.maxAge); + if (this.maxAge) this.expires = new Date(Date.now() + this.maxAge); if (this.path ) header += "; path=" + this.path if (this.expires ) header += "; expires=" + this.expires.toUTCString()