diff --git a/lib/response.js b/lib/response.js index f965e539dd2..77a3aad98c9 100644 --- a/lib/response.js +++ b/lib/response.js @@ -759,7 +759,10 @@ res.cookie = function (name, value, options) { if (opts.maxAge != null) { var maxAge = opts.maxAge - 0 - if (!isNaN(maxAge)) { + if (maxAge === Infinity || maxAge === -Infinity || (typeof opts.maxAge === 'number' && isNaN(maxAge))) { + // strip non-finite numeric maxAge (Infinity, -Infinity, NaN) + delete opts.maxAge + } else if (!isNaN(maxAge)) { opts.expires = new Date(Date.now() + maxAge) opts.maxAge = Math.floor(maxAge / 1000) }