Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Support for secure and session cookies #27

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bd42834
support secure cookies, apply changes from other forks that seemed to…
woloski Nov 20, 2012
b5d5405
remove extra semicolon on package.json
woloski Nov 20, 2012
ff19180
support for session cookies (i.e. not setting expires)
woloski Nov 20, 2012
31414ab
dont throw an error if cookie timed out (session or persistent)
woloski May 24, 2013
a192c15
update test to reflect new behavior on invalid cookie and too long co…
woloski May 24, 2013
46a21d4
refactor library and update crypto
Oct 22, 2018
3ae865b
update tests
Oct 22, 2018
3d18d96
Update Readme, add a section with the differences
Oct 22, 2018
fb6f167
Update package.json
Oct 22, 2018
0e816d4
Include .editorconfig file
Oct 22, 2018
bf28440
add httpOnly and secure flag in options but default true
Oct 22, 2018
fbaa52d
add support for samesite cookie flag
Oct 22, 2018
58dd48f
add options in table and mention cookie-parser
Oct 22, 2018
9778227
Merge pull request #2 from esarafianou/fixCrypto
esarafianou Oct 23, 2018
143ba2e
fix nit in readme
Oct 24, 2018
ec8b734
refactored library, overrode res.writeHeads
Oct 28, 2018
ef21d36
updated tests, added integration tests & coverage
Oct 28, 2018
84e6f12
Add CODEOWNERS file
Oct 30, 2018
0573744
Merge pull request #4 from auth0/codeowners
esarafianou Oct 30, 2018
b1fea32
update details in readme
Oct 28, 2018
f4f4de4
fix nit errors
Oct 30, 2018
7341810
Merge pull request #3 from esarafianou/fixCrypto
esarafianou Oct 30, 2018
ee14c81
fix small nit issues
Nov 5, 2018
53a8aae
Merge pull request #5 from esarafianou/readme
esarafianou Nov 5, 2018
b8349aa
Update lodash to a non vulnerable version
Jul 17, 2019
6c1b4e1
Fix bug in errors
Jul 17, 2019
3de6410
Merge pull request #6 from esarafianou/update_lodash
Jul 17, 2019
7572fb9
Add CHANGELOG file
Jul 17, 2019
80b1241
Release version 1.0.1
Jul 17, 2019
dfef400
Merge pull request #7 from esarafianou/bump1.0.1
Jul 18, 2019
27bc51f
fix: package.json & package-lock.json to reduce vulnerabilities
snyk-bot Feb 23, 2021
1e62691
Merge pull request #13 from auth0/snyk-fix-504eb9de22b3fa2efe963ab53a…
gkwang Aug 30, 2021
8031123
Upload OpsLevel YAML
sre-57-opslevel[bot] Oct 17, 2022
4d19ec4
Merge pull request #14 from auth0/SRE-57-Upload-opslevel-yaml
esarafianou Oct 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.nyc_output
coverage
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Change Log

All notable changes to this project will be documented in this file.

## v1.0.1 - 2019-07-17

### Misc

- Minor update in lodash to mitigate a snyk reported vulnerability
- Fixes bug in tests
- Minor updates in README

## v1.0.0 - 2018-10-30

### Adds

- Adds option for the samesite cookie flag
- Adds autoRenew option

### Changes

- Updates cryptographic algorithms. It's now using AES 256 in GCM mode

### Removes

- Removes the following exported functions:
- readSession
- readCookies
- checkLength
- headersToArray
- hmac_signature

### Misc

- Code refactor
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @auth0/product-security
68 changes: 45 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
# Cookie-Sessions

Secure cookie-based session middleware for
[Connect](http://github.com/senchalabs/connect). This is a new module and I
wouldn't recommend for production use just yet.
Secure cookie-based session middleware for Express.

Session data is stored on the request object in the 'session' property:
```js
var app = require('express');
var cookieParser = require('cookie-parser');
var cookieSessions = require('cookie-sessions');

var connect = require('connect'),
sessions = require('cookie-sessions');
app.use(
cookieSessions({
name: 'session_data',
secret: process.env.SECRET
})
);
```

Connect.createServer(
sessions({secret: '123abc'}),
function(req, res, next){
req.session = {'hello':'world'};
res.writeHead(200, {'Content-Type':'text/plain'});
res.end('session data updated');
}
).listen(8080);
The [cookie-parser](https://www.npmjs.com/package/cookie-parser) middleware
MUST also used.

The session data is JSON.stringified, encrypted and timestamped, then a HMAC
signature is attached to test for tampering. The main function accepts a
number of options:
The session data can be any JSON object. It's timestamped, encrypted and
authenticated automatically. The authenticated encryption uses `aes-256-gcm`
offered by the node `crypto` library. The httpOnly and secure cookie flags are
set by default.

* secret -- The secret to encrypt the session data with
* timeout -- The amount of time in miliseconds before the cookie expires
(default: 24 hours)
* session_key -- The cookie key name to store the session data in
(default: _node)
* path -- The path to use for the cookie (default: '/')
* domain -- (optional) Define a specific domain/subdomain scope for the cookie
The main function accepts a number of options:

| Option | Required | Description | Default |
|---------------|----------|-------------------------------------------------------------------------------------------------------------------------|----------|
| secret | Yes | The secret to encrypt the session data. | |
| timeout | Yes | The amount of time in milliseconds before the cookie expires. | 24 hours |
| name | Yes | The cookie name in which to store the session data. | `\_node` |
| path | Yes | The path to use for the cookie. | `/` |
| domain | No | Define a specific domain/subdomain scope for the cookie. | |
| autoRenew | No | Boolean: if true, a new cookie will be set in each response with an updated expiration Date.now() + timeout | true |
| httpOnly | No | Boolean: if true, the httpOnly cookie flag will be set. | true |
| secure | No | Boolean: if true, the secure cookie flag will be set. | true |
| sameSite | No | If set to "lax" or "strict", the sameSite cookie flag with the corresponding mode will be set. | |
| sessionCookie | No | Boolean: if true, it's considered a session cookie and no "expires" is set. | |


## Why store session data in cookies?
Expand All @@ -47,3 +56,16 @@ number of options:

__In summary:__ don't use cookie storage if you keep a lot of data in your
sessions!

## Migrating to version 1.0.0

* Any cookie created with 0.0.2 version will be invalidated.
* The `options` object has two naming changes:
* `name` instead of `session_key`
* `sessionCookie` instead of `session_cookie`
* The following exported functions have been removed:
* readSession
* readCookies
* checkLength
* headersToArray
* hmac\_signature
1 change: 0 additions & 1 deletion deps/nodeunit
Submodule nodeunit deleted from 0e1afe
Loading