Socket
Socket
Sign inDemoInstall

egg-cookies

Package Overview
Dependencies
Maintainers
5
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-cookies - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

9

History.md
2.2.2 / 2017-12-14
==================
**fixes**
* [[`d199238`](http://github.com/eggjs/egg-cookies/commit/d1992389558c24f26fbd6b617054c535e2c51319)] - fix: don't modify options (#9) (Roc Gao <<ggjqzjgp103@qq.com>>)
**others**
* [[`1037873`](http://github.com/eggjs/egg-cookies/commit/103787342f9b45bcc794ec2adeda5e809af3328b)] - chore: jsdoc typo (#6) (TZ | 天猪 <<atian25@qq.com>>)
2.2.1 / 2017-02-22

@@ -3,0 +12,0 @@ ==================

29

lib/cookies.js

@@ -46,8 +46,9 @@ 'use strict';

* @param {Object} opts - cookies' options
* - {Boolean} signed - defualt to true
* - {Boolean} encrypt - defualt to false
* - {Boolean} signed - default to true
* - {Boolean} encrypt - default to false
* @return {String} value - cookie's value
*/
get(name, opts) {
opts = encryptOrSigned(opts);
opts = opts || {};
const signed = computeSigned(opts);

@@ -61,6 +62,6 @@ const header = this.ctx.get('cookie');

let value = match[1];
if (!opts.encrypt && !opts.signed) return value;
if (!opts.encrypt && !signed) return value;
// signed
if (opts.signed) {
if (signed) {
const sigName = name + '.sig';

@@ -91,3 +92,4 @@ const sigValue = this.get(sigName, { signed: false });

set(name, value, opts) {
opts = encryptOrSigned(opts);
opts = opts || {};
const signed = computeSigned(opts);
value = value || '';

@@ -97,3 +99,2 @@ if (!this.secure && opts.secure) {

}
if (opts.secure === undefined) opts.secure = this.secure;

@@ -114,6 +115,10 @@ let headers = this.ctx.response.get('set-cookie') || [];

const cookie = new Cookie(name, value, opts);
// if user not set secure, reset secure to ctx.secure
if (opts.secure === undefined) cookie.attrs.secure = this.secure;
headers = pushCookie(headers, cookie);
// signed
if (opts.signed) {
if (signed) {
cookie.value = value && this.keys.sign(cookie.toString());

@@ -142,9 +147,7 @@ cookie.name += '.sig';

function encryptOrSigned(opts) {
opts = opts || {};
function computeSigned(opts) {
// encrypt default to false, signed default to true.
// disable singed when encrypt is true.
if (opts.encrypt) opts.signed = false;
if (opts.signed !== false) opts.signed = true;
return opts;
if (opts.encrypt) return false;
return opts.signed !== false;
}

@@ -151,0 +154,0 @@

{
"name": "egg-cookies",
"version": "2.2.1",
"version": "2.2.2",
"description": "cookies module for egg",

@@ -5,0 +5,0 @@ "files": [

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