I'm currently creating a Node app with Express and Passport and using this middleware in my main server.js file:
// Function to protect urls
function isProtected(req, res, next) {
if (req.isAuthenticated()) {
// User is logged in
res.locals.user = req.user;
return next();
}
// User is not logged in. Redirect to login.
res.redirect('login');
}
app.use('/protected_path', isProtected, protectedRouter);
My questions targets this line:
res.locals.user = req.user;
The user object is passed to res.locals so it can be used to populate fields like name, user role, date of registration, ...
Is there a way a user/website/api program (like Postman) can access the "res.locals" variables? There may be some sensitive data inside the req.user object and I just want to use the "res.locals" to get data which will be rendered in views like the profile page.
I could just pass the necessary variables into res.locals but this can get quite messy.
My last approach was to 'blacklist' the unnecessary variables described here: SO: How to omit specific properties from an object in JavaScript
Can the user access res.locals variables and therefore would it be security relevant? I would prefer my current solution if not.