question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hard Session Timeout

See original GitHub issue

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();
});

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
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.

0reactions
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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Session Timeout
This timeout defines the amount of time a session will remain active in case there is no activity by the user, closing and...
Read more >
Hard session timeout
A Hard session timeout is a defined timeout period for the user session irrespective of user activity; if the application has a hard...
Read more >
Session Hard Timeout
Session Hard Timeout. Question. Hello Developer,. I want to set session hard timeout to 4 hours .How should I do? BestRegards. Phyo Aung....
Read more >
Session Timeout - an overview
Typical session timeouts are 15- to 45-minute durations depending on the sensitivity of the data that may be exposed. As the session timeout...
Read more >
Insufficient Session Expiration
Insufficient Session Expiration occurs when a Web application permits an attacker to reuse old session credentials or session IDs for authorization.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found