
Research
Security News
Lazarus Strikes npm Again with New Wave of Malicious Packages
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
next-session
Advanced tools
Simple session middleware for Next.js 9 API Routes.
npm install --save next-session
import session from 'next-session';
const handler = (req, res) => {
if (req.session.views) {
// On later visits, increase # of views by one on every request
req.session.views += 1;
} else {
// On first visit, set # of views to 1
req.session.views = 1;
}
res.send(`In this session, you have visited this page ${req.session.views} time(s).`)
};
// wrap handler with session middleware and include options
export default session(handler, {
name: 'sid',
cookies: {
secure: true,
maxAge: 1209600000,
},
});
Create a session middleware for handler
with the given options
.
See Next.js 9 API Routes.
next-session
accepts the properties below.
options | description | default |
---|---|---|
name | The name of the cookie to be read from the request and set to the response. | sessionId |
store | The session store instance to be used. | MemoryStore |
generateId | The function to generate a new session ID. This needs to be a function that returns a string. | crypto.randomBytes(16).toString('hex') |
cookie.secure | Specifies the boolean value for the Secure Set-Cookie attribute. If set to true, cookie is only sent to the server with an encrypted request over the HTTPS protocol. | false |
cookie.httpOnly | Specifies the boolean value for the httpOnly Set-Cookie attribute. If set to true, cookies are inaccessible to client-side scripts. This is yo help mitigate cross-site scripting (XSS) attacks. | true |
cookie.path | Specifies the value for the Path Set-Cookie attribute. This indicates a URL path that must exist in the requested URL in order to send the Cookie header | unset |
cookie.domain | Specifies the value for the Domain Set-Cookie attribute. Only allowed hosts to receive the cookie. If unspecified, it defaults to the host of the current document location, excluding subdomains. If Domain is specified, then subdomains are always included. | unset |
cookie.sameSite | Specifies the value for the SameSite Set-Cookie attribute. This lets servers require that a cookie shouldn't be sent with cross-site (where Site is defined by Domain attribute) requests, which provides some protection against cross-site request forgery attacks ( CSRF). | unset |
cookie.maxAge | Specifies the value for the Max-Age Set-Cookie attribute. The value must be in miliseconds. Determine the length of time before the cookies expire. If unspecified, the cookies will expire when the client closes (Session cookies). | unset (Session) |
This allows you to set or get a specific value that associates to the current session.
// Set a value
if (loggedIn) req.session.user = 'John Doe';
// Get a value
const currentUser = req.session.user; // "John Doe"
Destroy to current session and remove it from session store.
if (loggedOut) req.session.destroy();
The unique id that associates to the current session. This should not be modified.
The session store to use for session middleware (see options
above).
A compatible session store must include three functions: set(sid)
, get(sid)
, and destroy()
.
All functions should return Promises (callbacks are not supported). For an example of a session store implementation, see MemoryStore
.
Make a PR to add your own compatible stores here.
Please see my contributing.md.
FAQs
Simple promise-based session for Next.js
We found that next-session 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
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.
Security News
Opengrep continues building momentum with the alpha release of its Playground tool, demonstrating the project's rapid evolution just two months after its initial launch.