Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard Session Timeout #353

Closed
einfallstoll opened this issue Apr 9, 2020 · 7 comments
Closed

Hard Session Timeout #353

einfallstoll opened this issue Apr 9, 2020 · 7 comments
Labels

Comments

@einfallstoll
Copy link

einfallstoll commented Apr 9, 2020

As far as I understand, the ttl is a session inactivity timeout. So, if a user is not actively using a session, it will expire after the specified duration. From a security perspective, we want to keep this as low as possible (less than an hour). However, if a user's session can be stolen, the attacker can repeatedly extend the session's life by sending requests on a regular basis (e.g. every few minutes). To prevent a session from being extended indefinitely one has to set a hard session timeout which will expire sessions even though they are actively used and set this to a reasonable amount of time (a company can expect the user to login once or twice a day, so a hard session timeout of 4-12 hours is reasonable).

I studied the documentation and it seems like a hard session timeout is not implemented... yet. And I think I have to implement this on my own (e.g. store the login time in the session and compare this on every request against the maximum duration).

So this raises the following questions:

  • Is my understanding of ttl correct?
  • Is a hard session timeout really not implemented?
  • Would it make sense to implement this in this module?

For anyone looking for an implementation of a hard session timeout. This is how I solved it:

router.use(passport.initialize());
router.use(passport.session());
router.use((req, res, next) => {
  if (req.user && !req.session.hardExpiration) {
    req.session.hardExpiration = moment().add(12, 'hours').toDate();
  } else if (moment().isAfter(req.session.hardExpiration)) {
    req.logout();
  }
  next();
});
@stale
Copy link

stale bot commented Jun 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 8, 2020
@einfallstoll
Copy link
Author

It would not be stale, if it wasn't ignored 🤦🏻‍♂️

@stale stale bot removed the wontfix label Jun 8, 2020
@mingchuno
Copy link
Collaborator

mingchuno commented Jul 20, 2020

@einfallstoll

Have you try the resave, rolling and saveUninitialized options in express-session. Does it help?
https://github.com/expressjs/session#resave

@einfallstoll
Copy link
Author

@mingchuno Does rolling work along with ttl? So ttl would be the maximum of an inactive session and maxAge the maximum of an active session?

@mingchuno
Copy link
Collaborator

@einfallstoll You may need to test it yourself 🙏 and share the findings here.

@mingchuno
Copy link
Collaborator

mingchuno commented Jul 20, 2020

may relate to #351

@stale
Copy link

stale bot commented Sep 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 18, 2020
@stale stale bot closed this as completed Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants