Problem
Login endpoint returns req.user directly (line 35 of auth.js), which includes password hash and potentially sensitive fields.
Technical Details
File: backend/routes/auth.js
Line: 35
res.status(200).json({ message: 'Login successful', user: req.user });
This returns entire user document including password hash.
Risk
- Password hash exposed in response
- If response is logged/cached, hash accessible
- Additional fields may be unintentionally exposed
- Expands attack surface
Recommended Solution
Return only safe user fields:
router.post("/login", validateRequest(loginSchema),
passport.authenticate('local'),
(req, res) => {
// Extract only safe fields
const safeUser = {
id: req.user._id,
username: req.user.username,
email: req.user.email,
// Don't include: password, passwordHash, __v
};
res.status(200).json({
message: 'Login successful',
user: safeUser
});
}
);
// Or define a toJSON method in User model
UserSchema.methods.toJSON = function() {
const obj = this.toObject();
delete obj.password; // Exclude password from JSON
return obj;
};
// Then simpler response
res.status(200).json({
message: 'Login successful',
user: req.user.toJSON()
});
Testing Strategy
Program Template
Suggested Labels
security, data-exposure, authentication, gssoc-eligible
Problem
Login endpoint returns
req.userdirectly (line 35 of auth.js), which includes password hash and potentially sensitive fields.Technical Details
File:
backend/routes/auth.jsLine: 35
This returns entire user document including password hash.
Risk
Recommended Solution
Return only safe user fields:
Testing Strategy
Program Template
Suggested Labels
security, data-exposure, authentication, gssoc-eligible