
Research
/Security News
OpenAPI React Query Codegen Compromised in Mini Shai-Hulud npm Supply Chain Attack
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.
ensure-login
Advanced tools
Login session ensuring middleware for Connect/Express.
Based on jaredhanson's connect-ensure-login, with these additions:
baseUrl parameter that allows redirects behind Nginx and Apache.setReturnTo accepts a regular expression: the URL is remembered only if it matches.setReturnWhenXhr is true) and it only remembers GET requests.This middleware ensures that a user is logged in. If a request is received that is unauthenticated, the request will be redirected to a login page. The URL will be saved in the session, so the user can be conveniently returned to the page that was originally requested.
$ npm install ensure-login
In this example, an application has a settings page where preferences can be configured. A user must be logged in before accessing this page.
app.get('/settings',
ensureLoggedIn({baseUrl:'/', redirectTo:'/login', setReturnTo:/^([^/]*|.*\/)[^.]+$/}),
function(req, res) {
res.render('settings', { user: req.user });
});
If a user is not logged in when attempting to access this page, the request will
be redirected to /login and the original request URL (/settings) will be
saved to the session at req.session.returnTo.
This middleware integrates seamlessly with Passport.
Simply mount Passport's authenticate() middleware at the login route.
app.get('/login', function(req, res) {
res.render('login');
});
app.post('/login',
passport.authenticate('local', {
successReturnToOrRedirect: '/',
failureRedirect: '/login'
})
);
Upon log in, Passport will notice the returnTo URL saved in the session and
redirect the user back to /settings.
If the user is not logged in, the sequence of requests and responses that take place during this process can be confusing. Here is a step-by-step overview of what happens:
GET /settings
session.returnTo to /settings/loginGET /login
POST /login
session.returnTo and redirects to /settingsGET /settings
| option | default | type | meaning |
|---|---|---|---|
redirectTo | '/login' | string | URL to redirect to for login |
setReturnTo | true | boolean or RegExp | set the URL in the session, always or when it matches the RegExp |
baseUrl | '/' | string | URL of the base where redirectTo is mounted |
setReturnWhenXhr | false | boolean | include AJAX calls when remembering the return URL |
$ npm install
$ npm test
FAQs
Login session ensuring middleware for Connect.
The npm package ensure-login receives a total of 41 weekly downloads. As such, ensure-login popularity was classified as not popular.
We found that ensure-login demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.

Security News
Socket joins more than 100 technology, cybersecurity, and financial organizations calling for a global surge in cyber defense.

Product
Enterprise security teams can now detect malware, credential theft, suspicious network activity, and risky updates across Microsoft Edge extensions.