pax_global_header00006660000000000000000000000064143771671150014526gustar00rootroot0000000000000052 comment=0167b2d857780f6b3d8919bb7702ab1a1af05ae7 node-cookie-signature-1.2.1/000077500000000000000000000000001437716711500157225ustar00rootroot00000000000000node-cookie-signature-1.2.1/.gitignore000066400000000000000000000000151437716711500177060ustar00rootroot00000000000000node_modules node-cookie-signature-1.2.1/.npmignore000066400000000000000000000000351437716711500177170ustar00rootroot00000000000000support test examples *.sock node-cookie-signature-1.2.1/History.md000066400000000000000000000022461437716711500177110ustar00rootroot000000000000001.2.1 / 2022-02-27 ================== * update annotations for allowed secret key types (#44, thanks @jyasskin!) 1.2.0 / 2022-02-17 ================== * allow buffer and other node-supported types as key (#33) * be pickier about extra content after signed portion (#40) * some internal code clarity/cleanup improvements (#26) 1.1.0 / 2018-01-18 ================== * switch to built-in `crypto.timingSafeEqual` for validation instead of previous double-hash method (thank you @jodevsa!) 1.0.6 / 2015-02-03 ================== * use `npm test` instead of `make test` to run tests * clearer assertion messages when checking input 1.0.5 / 2014-09-05 ================== * add license to package.json 1.0.4 / 2014-06-25 ================== * corrected avoidance of timing attacks (thanks @tenbits!) 1.0.3 / 2014-01-28 ================== * [incorrect] fix for timing attacks 1.0.2 / 2014-01-28 ================== * fix missing repository warning * fix typo in test 1.0.1 / 2013-04-15 ================== * Revert "Changed underlying HMAC algo. to sha512." * Revert "Fix for timing attacks on MAC verification." 0.0.1 / 2010-01-03 ================== * Initial release node-cookie-signature-1.2.1/LICENSE000066400000000000000000000021441437716711500167300ustar00rootroot00000000000000(The MIT License) Copyright (c) 2012–2023 LearnBoost and other contributors; Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-cookie-signature-1.2.1/Readme.md000066400000000000000000000006531437716711500174450ustar00rootroot00000000000000 # cookie-signature Sign and unsign cookies. ## Example ```js var cookie = require('cookie-signature'); var val = cookie.sign('hello', 'tobiiscool'); val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); var val = cookie.sign('hello', 'tobiiscool'); cookie.unsign(val, 'tobiiscool').should.equal('hello'); cookie.unsign(val, 'luna').should.be.false; ``` ## License MIT. See LICENSE file for details. node-cookie-signature-1.2.1/index.js000066400000000000000000000026051437716711500173720ustar00rootroot00000000000000/** * Module dependencies. */ var crypto = require('crypto'); /** * Sign the given `val` with `secret`. * * @param {String} val * @param {String|NodeJS.ArrayBufferView|crypto.KeyObject} secret * @return {String} * @api private */ exports.sign = function(val, secret){ if ('string' != typeof val) throw new TypeError("Cookie value must be provided as a string."); if (null == secret) throw new TypeError("Secret key must be provided."); return val + '.' + crypto .createHmac('sha256', secret) .update(val) .digest('base64') .replace(/\=+$/, ''); }; /** * Unsign and decode the given `input` with `secret`, * returning `false` if the signature is invalid. * * @param {String} input * @param {String|NodeJS.ArrayBufferView|crypto.KeyObject} secret * @return {String|Boolean} * @api private */ exports.unsign = function(input, secret){ if ('string' != typeof input) throw new TypeError("Signed cookie string must be provided."); if (null == secret) throw new TypeError("Secret key must be provided."); var tentativeValue = input.slice(0, input.lastIndexOf('.')), expectedInput = exports.sign(tentativeValue, secret), expectedBuffer = Buffer.from(expectedInput), inputBuffer = Buffer.from(input); return ( expectedBuffer.length === inputBuffer.length && crypto.timingSafeEqual(expectedBuffer, inputBuffer) ) ? tentativeValue : false; }; node-cookie-signature-1.2.1/package.json000066400000000000000000000010411437716711500202040ustar00rootroot00000000000000{ "name": "cookie-signature", "version": "1.2.1", "description": "Sign and unsign cookies", "keywords": ["cookie", "sign", "unsign"], "author": "TJ Holowaychuk ", "license": "MIT", "repository": { "type": "git", "url": "https://github.com/visionmedia/node-cookie-signature.git" }, "dependencies": {}, "engines": { "node": ">=6.6.0" }, "devDependencies": { "mocha": "*", "should": "*" }, "scripts": { "test": "mocha --require should --reporter spec" }, "main": "index" } node-cookie-signature-1.2.1/test/000077500000000000000000000000001437716711500167015ustar00rootroot00000000000000node-cookie-signature-1.2.1/test/index.js000066400000000000000000000031701437716711500203470ustar00rootroot00000000000000/** * Module dependencies. */ var cookie = require('..'); describe('.sign(val, secret)', function(){ it('should sign the cookie', function(){ var val = cookie.sign('hello', 'tobiiscool'); val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); var val = cookie.sign('hello', 'luna'); val.should.not.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); }) it('should accept appropriately non-string secrets', function(){ var key = Buffer.from("A0ABBC0C", 'hex'), val = cookie.sign('hello', key); val.should.equal('hello.hIvljrKw5oOZtHHSq5u+MlL27cgnPKX77y7F+x5r1to'); (function () { cookie.sign('unsupported', new Date()); }).should.throw(); }) }) describe('.unsign(val, secret)', function(){ it('should unsign the cookie', function(){ var val = cookie.sign('hello', 'tobiiscool'); cookie.unsign(val, 'tobiiscool').should.equal('hello'); cookie.unsign(val, 'luna').should.be.false(); }) it('should reject malformed cookies', function(){ var pwd = 'actual sekrit password'; cookie.unsign('fake unsigned data', pwd).should.be.false(); var val = cookie.sign('real data', pwd); cookie.unsign('garbage'+val, pwd).should.be.false(); cookie.unsign('garbage.'+val, pwd).should.be.false(); cookie.unsign(val+'.garbage', pwd).should.be.false(); cookie.unsign(val+'garbage', pwd).should.be.false(); }) it('should accept non-string secrets', function(){ var key = Uint8Array.from([0xA0, 0xAB, 0xBC, 0x0C]), val = cookie.unsign('hello.hIvljrKw5oOZtHHSq5u+MlL27cgnPKX77y7F+x5r1to', key); val.should.equal('hello'); }) })