006ReviewseniorJavaScript / Node Security真实来源改编 tough-cookie
tough-cookie:修复 cookie domain 的原型污染
审查一个声称修复 tough-cookie CookieJar 原型污染 PoC(Domain=__proto__)的补丁:它在写入 cookie 前拦截 __proto__ 这个 domain。
@@ -41,7 +41,11 @@ MemoryCookieStore.prototype.findCookies = function (domain, path, cb) { cb(null, results) } MemoryCookieStore.prototype.putCookie = function (cookie, cb) {+ // A cookie with Domain=__proto__ walks the prototype chain when we build+ // the domain index below and pollutes Object.prototype+ // (GHSA-72xf-g2v4-qvf3). Drop it before it is ever stored.+ if (cookie.domain === '__proto__') return cb(null) if (!this.idx[cookie.domain]) this.idx[cookie.domain] = {} if (!this.idx[cookie.domain][cookie.path]) this.idx[cookie.domain][cookie.path] = {} this.idx[cookie.domain][cookie.path][cookie.key] = cookie cb(null) }@@ -10,6 +10,16 @@ vows }, }, }) + .addBatch({+ 'ignores __proto__ cookie domains': {+ topic: function () {+ const jar = new CookieJar()+ jar.setCookie('a=b; Domain=__proto__; Path=/', 'https://__proto__/', this.callback)+ },+ 'does not pollute Object.prototype': function () {+ assert.equal({}.a, undefined)+ },+ },+ }) .export(module)