Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jaredhanson/passport
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5e6d92f1ef2adf21b54492cc86a7c066ef3f1e98
Choose a base ref
...
head repository: jaredhanson/passport
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c33067bc5aa81a6dd827076d810bf788bb6acac7
Choose a head ref

Commits on May 17, 2022

  1. Copy the full SHA
    7e9b9cf View commit details
  2. Fix tests.

    jaredhanson committed May 17, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a7513c4 View commit details

Commits on May 18, 2022

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a77271f View commit details
  2. Copy the full SHA
    9cde808 View commit details
  3. Copy the full SHA
    c018dea View commit details
  4. Fix tests.

    jaredhanson committed May 18, 2022
    Copy the full SHA
    fa80b20 View commit details
  5. Copy the full SHA
    fa70e2f View commit details
  6. Copy the full SHA
    88c1f1b View commit details

Commits on May 19, 2022

  1. Add test.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    71c54f6 View commit details
  2. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    cc7606c View commit details
  3. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    ee0bf81 View commit details
  4. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    cfa8259 View commit details
  5. Clean up tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    b395106 View commit details
  6. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    3001654 View commit details
  7. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    80cc4e3 View commit details
  8. Copy the full SHA
    294f22c View commit details
  9. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    c1991cf View commit details
  10. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    8825a9a View commit details
  11. Copy the full SHA
    e69834e View commit details
  12. Copy the full SHA
    a349c2b View commit details
  13. Copy the full SHA
    17111d7 View commit details
  14. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    bfba8a1 View commit details
  15. Copy the full SHA
    29a90d6 View commit details
  16. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    f8a175f View commit details
  17. Add tests.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    987b191 View commit details
  18. Silence verbose logging.

    jaredhanson committed May 19, 2022
    Copy the full SHA
    46756e5 View commit details
  19. Copy the full SHA
    4f6bd5b View commit details

Commits on May 20, 2022

  1. Copy the full SHA
    8dd79fe View commit details
  2. Merge pull request #900 from jaredhanson/fix-fixation

    Address Session Fixation Concerns
    jaredhanson authored May 20, 2022
    Copy the full SHA
    42630cb View commit details
  3. Update changelog.

    jaredhanson committed May 20, 2022
    Copy the full SHA
    3052bb4 View commit details
  4. 0.6.0

    jaredhanson committed May 20, 2022
    Copy the full SHA
    c33067b View commit details
Showing with 734 additions and 248 deletions.
  1. +9 −1 CHANGELOG.md
  2. +13 −3 lib/http/request.js
  3. +71 −14 lib/sessionmanager.js
  4. +0 −219 package-lock.json
  5. +3 −2 package.json
  6. +638 −9 test/http/request.test.js
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.0] - 2022-05-20
### Security

- Improved robustness against session fixation attacks in cases where there is
physical access to the same system or the application is susceptible to
cross-site scripting (XSS).

## [0.5.3] - 2022-05-16
### Fixed

@@ -50,7 +57,8 @@ eliminating a race condition in situations where `initialize()` middleware is
used multiple times in an application with `userProperty` set to different
values.

[Unreleased]: https://github.com/jaredhanson/passport/compare/v0.5.3...HEAD
[Unreleased]: https://github.com/jaredhanson/passport/compare/v0.6.0...HEAD
[0.6.0]: https://github.com/jaredhanson/passport/compare/v0.5.3...v0.6.0
[0.5.3]: https://github.com/jaredhanson/passport/compare/v0.5.2...v0.5.3
[0.5.2]: https://github.com/jaredhanson/passport/compare/v0.5.1...v0.5.2
[0.5.1]: https://github.com/jaredhanson/passport/compare/v0.5.0...v0.5.1
16 changes: 13 additions & 3 deletions lib/http/request.js
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ req.logIn = function(user, options, done) {
if (typeof done != 'function') { throw new Error('req#login requires a callback function'); }

var self = this;
this._sessionManager.logIn(this, user, function(err) {
this._sessionManager.logIn(this, user, options, function(err) {
if (err) { self[property] = null; return done(err); }
done();
});
@@ -51,12 +51,22 @@ req.logIn = function(user, options, done) {
* @api public
*/
req.logout =
req.logOut = function() {
req.logOut = function(options, done) {
if (typeof options == 'function') {
done = options;
options = {};
}
options = options || {};

var property = this._userProperty || 'user';

this[property] = null;
if (this._sessionManager) {
this._sessionManager.logOut(this);
if (typeof done != 'function') { throw new Error('req#logout requires a callback function'); }

this._sessionManager.logOut(this, options, done);
} else {
done && done();
}
};

85 changes: 71 additions & 14 deletions lib/sessionmanager.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var merge = require('utils-merge');

function SessionManager(options, serializeUser) {
if (typeof options == 'function') {
serializeUser = options;
@@ -9,30 +11,85 @@ function SessionManager(options, serializeUser) {
this._serializeUser = serializeUser;
}

SessionManager.prototype.logIn = function(req, user, cb) {
SessionManager.prototype.logIn = function(req, user, options, cb) {
if (typeof options == 'function') {
cb = options;
options = {};
}
options = options || {};

if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); }

var self = this;
this._serializeUser(user, req, function(err, obj) {
var prevSession = req.session;

// regenerate the session, which is good practice to help
// guard against forms of session fixation
req.session.regenerate(function(err) {
if (err) {
return cb(err);
}
// TODO: Error if session isn't available here.
if (!req.session) {
req.session = {};
}
if (!req.session[self._key]) {
req.session[self._key] = {};
}
req.session[self._key].user = obj;
cb();

self._serializeUser(user, req, function(err, obj) {
if (err) {
return cb(err);
}
if (options.keepSessionInfo) {
merge(req.session, prevSession);
}
if (!req.session[self._key]) {
req.session[self._key] = {};
}
// store user information in session, typically a user id
req.session[self._key].user = obj;
// save the session before redirection to ensure page
// load does not happen before session is saved
req.session.save(function(err) {
if (err) {
return cb(err);
}
cb();
});
});
});
}

SessionManager.prototype.logOut = function(req, cb) {
if (req.session && req.session[this._key]) {
SessionManager.prototype.logOut = function(req, options, cb) {
if (typeof options == 'function') {
cb = options;
options = {};
}
options = options || {};

if (!req.session) { return cb(new Error('Login sessions require session support. Did you forget to use `express-session` middleware?')); }

var self = this;

// clear the user from the session object and save.
// this will ensure that re-using the old session id
// does not have a logged in user
if (req.session[this._key]) {
delete req.session[this._key].user;
}
var prevSession = req.session;

cb && cb();
req.session.save(function(err) {
if (err) {
return cb(err)
}

// regenerate the session, which is good practice to help
// guard against forms of session fixation
req.session.regenerate(function(err) {
if (err) {
return cb(err);
}
if (options.keepSessionInfo) {
merge(req.session, prevSession);
}
cb();
});
});
}


219 changes: 0 additions & 219 deletions package-lock.json

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport",
"version": "0.5.3",
"version": "0.6.0",
"description": "Simple, unobtrusive authentication for Node.js.",
"keywords": [
"express",
@@ -36,7 +36,8 @@
"main": "./lib",
"dependencies": {
"passport-strategy": "1.x.x",
"pause": "0.0.1"
"pause": "0.0.1",
"utils-merge": "^1.0.1"
},
"devDependencies": {
"make-node": "0.3.x",
647 changes: 638 additions & 9 deletions test/http/request.test.js

Large diffs are not rendered by default.