Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cookie-session

Package Overview
Dependencies
Maintainers
6
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cookie-session - npm Package Compare versions

Comparing version 2.0.0-alpha.1 to 2.0.0-alpha.2

8

HISTORY.md

@@ -0,1 +1,9 @@

2.0.0-alpha.2 / 2016-11-10
==========================
* deps: cookies@0.6.1
* deps: debug@2.3.2
- Fix error when running under React Native
- deps: ms@0.7.2
2.0.0-alpha.1 / 2015-10-11

@@ -2,0 +10,0 @@ ==========================

72

index.js

@@ -15,5 +15,5 @@ /*!

var debug = require('debug')('cookie-session');
var Cookies = require('cookies');
var onHeaders = require('on-headers');
var debug = require('debug')('cookie-session')
var Cookies = require('cookies')
var onHeaders = require('on-headers')

@@ -41,3 +41,3 @@ /**

function cookieSession(options) {
function cookieSession (options) {
var opts = options || {}

@@ -49,16 +49,18 @@

// secrets
var keys = opts.keys;
if (!keys && opts.secret) keys = [opts.secret];
var keys = opts.keys
if (!keys && opts.secret) keys = [opts.secret]
// defaults
if (null == opts.overwrite) opts.overwrite = true;
if (null == opts.httpOnly) opts.httpOnly = true;
if (null == opts.signed) opts.signed = true;
if (opts.overwrite == null) opts.overwrite = true
if (opts.httpOnly == null) opts.httpOnly = true
if (opts.signed == null) opts.signed = true
if (!keys && opts.signed) throw new Error('.keys required.');
if (!keys && opts.signed) throw new Error('.keys required.')
debug('session options %j', opts);
debug('session options %j', opts)
return function _cookieSession(req, res, next) {
var cookies = req.sessionCookies = new Cookies(req, res, keys);
return function _cookieSession (req, res, next) {
var cookies = req.sessionCookies = new Cookies(req, res, {
keys: keys
})
var sess

@@ -70,3 +72,3 @@

req.__defineGetter__('session', function getSession() {
req.__defineGetter__('session', function getSession () {
// already retrieved

@@ -86,3 +88,3 @@ if (sess) {

req.__defineSetter__('session', function setSession(val) {
req.__defineSetter__('session', function setSession (val) {
if (val == null) {

@@ -103,6 +105,6 @@ // unset session

onHeaders(res, function setHeaders() {
onHeaders(res, function setHeaders () {
if (sess === undefined) {
// not accessed
return;
return
}

@@ -121,5 +123,5 @@

}
});
})
next();
next()
}

@@ -136,3 +138,3 @@ };

function Session(ctx, obj) {
function Session (ctx, obj) {
Object.defineProperty(this, '_ctx', {

@@ -154,3 +156,3 @@ value: ctx

Session.create = function create(req, obj) {
Session.create = function create (req, obj) {
var ctx = new SessionContext(req)

@@ -165,3 +167,3 @@ return new Session(ctx, obj)

Session.deserialize = function deserialize(req, str) {
Session.deserialize = function deserialize (req, str) {
var ctx = new SessionContext(req)

@@ -181,3 +183,3 @@ var obj = decode(str)

Session.serialize = function serialize(sess) {
Session.serialize = function serialize (sess) {
return encode(sess)

@@ -194,3 +196,3 @@ }

Object.defineProperty(Session.prototype, 'isChanged', {
get: function getIsChanged() {
get: function getIsChanged () {
return this._ctx._new || this._ctx._val !== Session.serialize(this)

@@ -208,3 +210,3 @@ }

Object.defineProperty(Session.prototype, 'isNew', {
get: function getIsNew() {
get: function getIsNew () {
return this._ctx._new

@@ -223,3 +225,3 @@ }

Object.defineProperty(Session.prototype, 'length', {
get: function getLength() {
get: function getLength () {
return Object.keys(this).length

@@ -237,3 +239,3 @@ }

Object.defineProperty(Session.prototype, 'isPopulated', {
get: function getIsPopulated() {
get: function getIsPopulated () {
return Boolean(this.length)

@@ -248,3 +250,3 @@ }

Session.prototype.save = function save() {
Session.prototype.save = function save () {
var ctx = this._ctx

@@ -268,3 +270,3 @@ var val = Session.serialize(this)

function SessionContext(req) {
function SessionContext (req) {
this.req = req

@@ -281,3 +283,3 @@

function createSession(req) {
function createSession (req) {
debug('new session')

@@ -295,5 +297,5 @@ return Session.create(req)

function decode(string) {
var body = new Buffer(string, 'base64').toString('utf8');
return JSON.parse(body);
function decode (string) {
var body = new Buffer(string, 'base64').toString('utf8')
return JSON.parse(body)
}

@@ -309,3 +311,3 @@

function encode(body) {
function encode (body) {
var str = JSON.stringify(body)

@@ -320,3 +322,3 @@ return new Buffer(str).toString('base64')

function tryGetSession(req) {
function tryGetSession (req) {
var cookies = req.sessionCookies

@@ -323,0 +325,0 @@ var name = req.sessionKey

{
"name": "cookie-session",
"description": "cookie session middleware",
"repository": "expressjs/cookie-session",
"version": "2.0.0-alpha.1",
"version": "2.0.0-alpha.2",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
],
"license": "MIT",
"keywords": [

@@ -12,11 +16,17 @@ "connect",

],
"repository": "expressjs/cookie-session",
"dependencies": {
"cookies": "0.5.1",
"debug": "~2.2.0",
"cookies": "0.6.1",
"debug": "2.3.2",
"on-headers": "~1.0.1"
},
"devDependencies": {
"connect": "3.4.0",
"istanbul": "0.3.22",
"mocha": "2.3.3",
"connect": "3.5.0",
"eslint": "3.9.1",
"eslint-config-standard": "6.2.1",
"eslint-plugin-markdown": "1.0.0-beta.3",
"eslint-plugin-promise": "3.3.1",
"eslint-plugin-standard": "2.0.1",
"istanbul": "0.4.5",
"mocha": "2.5.3",
"supertest": "1.1.0"

@@ -30,4 +40,7 @@ },

],
"license": "MIT",
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"lint": "eslint --plugin markdown --ext js,md .",
"test": "mocha --check-leaks --reporter spec --bail test/",

@@ -34,0 +47,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot test/",

@@ -11,10 +11,8 @@ # cookie-session

## Semantics
## Install
This module provides "guest" sessions, meaning any visitor will have a session,
authenticated or not. If a session is _new_ a `Set-Cookie` will be produced regardless
of populating the session.
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
## Install
```bash

@@ -28,2 +26,13 @@ $ npm install cookie-session

var cookieSession = require('cookie-session')
var express = require('express')
var app = express()
app.use(cookieSession({
name: 'session',
keys: [/* secret keys */],
// Cookie Options
maxAge: 24 * 60 * 60 * 1000 // 24 hours
}))
```

@@ -33,4 +42,13 @@

Create a new cookie session middleware with the provided options.
Create a new cookie session middleware with the provided options. This middleware
will attach the property `session` to `req`, which provides an object representing
the loaded session. This session is either a new session if no valid session was
provided in the request, or a loaded session from the request.
The middleware will automatically add a `Set-Cookie` header to the response if the
contents of `req.session` were altered. _Note_ that no `Set-Cookie` header will be
in the response (and thus no session created for a specific user) unless there are
contents in the session, so be sure to add something to `req.session` as soon as
you have identifying information to store for the session.
#### Options

@@ -67,3 +85,2 @@

- `secure`: a boolean indicating whether the cookie is only to be sent over HTTPS (`false` by default for HTTP, `true` by default for HTTPS).
- `secureProxy`: a boolean indicating whether the cookie is only to be sent over HTTPS (use this if you handle SSL not in your node process).
- `httpOnly`: a boolean indicating whether the cookie is only to be sent over HTTP(S), and not made available to client JavaScript (`true` by default).

@@ -97,5 +114,5 @@ - `signed`: a boolean indicating whether the cookie is to be signed (`true` by default). If this is true, another cookie of the same name with the `.sig` suffix appended will also be sent, with a 27-byte url-safe base64 SHA1 value representing the hash of _cookie-name_=_cookie-value_ against the first [Keygrip](https://github.com/expressjs/keygrip) key. This signature key is used to detect tampering the next time a cookie is received.

To destroy a session simply set it to `null`:
To destroy a session simply set it to `null`:
```js
```
req.session = null

@@ -121,3 +138,3 @@ ```

app.use(function (req, res, next) {
app.get('/', function (req, res, next) {
// Update views

@@ -124,0 +141,0 @@ req.session.views = (req.session.views || 0) + 1

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