Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
session-helper
Advanced tools
Session helper is a module that helps you save an expiry time to your local/session storage, be able to performs checks against it, and perform callbacks when this expiry time has been reached.
Session Helper is a module that helps you save a timestamp as an 'expiry time' to your local/session storage to be able to perform checks against it and to trigger callbacks when this expiry time has been reached.
npm install session-helper --save
// es6
import SessionHelper from 'session-helper'
export default new SessionHelper(
"123-my-unique-id-here", // uuid
"localStorage", // cache location: choose between 'localStorage' or 'sessionStorage'
30, // timeout in minutes
true, // debugMode, 'false' by default, enable it to push log messages to console
)
// es5
const SessionHelper = require('session-helper')
const sessionHelper = new SessionHelper(
"123-my-unique-id-here", // uuid
"localStorage", // cache location: choose between 'localStorage' or 'sessionStorage'
30, // timeout in minutes
true, // debugMode, 'false' by default, enable it to push log messages to console
)
Function to get expiry from storage:
let expiryFromStorage = SessionHelper.expiry
Function to set expiry from storage:
SessionHelper.setExpiry()
Function to remove expiry from storage:
SessionHelper.removeExpiry()
Boolean to check if expiry in storage is set and is expired:
let isTokenExpired = SessionHelper.isTokenExpired
Boolean to check if expiry in storage is set and if it is expired, or if it is not even set:
let isTokenExpiredOrNull = SessionHelper.isTokenExpiredOrNull
Important: It can be null when, for example, there are two tabs (or more) open and the first tab has called
removeExpiry()
before the second. Then the expiry will be null in the second, meaning the Session Helper would interpret it as "it is not set" instead of "it is set and expired" because of the other tab. This might be useful when an expiry had to log out a user in the first tab and thus in the second there can be checked if the user is still logged in or not by checking theisTokenExpiredOrNull
boolean.
Boolean to get the amount of time left in seconds until the expiry is reached (if the timer has started and the callback is set):
let timeLeftUntilExpiryIsReached = SessionHelper.expiryTimeout
Variable to set a callback function which will trigger when the timeout function ends:
SessionHelper.expiryTimeoutCallback = function() {
console.log('Expiry has been reached')
// perform actions like a logout
}
To get the callback function which will be triggered at the end of the timeout function:
let callback = SessionHelper.expiryTimeoutCallback
You can trigger this callback manually by adding extra parentheses like so:
SessionHelper.expiryTimeoutCallback()
Function to start the timeout function, using the timeoutInMinutes configuration parameter:
SessionHelper.startExpiryTimeout()
Function to stop the timeout function:
SessionHelper.stopExpiryTimeout()
Function to restart the timeout function, using the timeoutInMinutes configuration parameter. Internally it's simply calling .stopExpiryTimeout and .startExpiryTimeout:
SessionHelper.resetExpiryTimeout()
PRs are more than welcome and will be reviewed asap!
MIT - For full license see the LICENSE file.
FAQs
Session helper is a module that helps you save an expiry time to your local/session storage, be able to performs checks against it, and perform callbacks when this expiry time has been reached.
We found that session-helper demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.