Skip to content

Commit 434bed1

Browse files
committed
Filter sensitive user data from login endpoint response (Issue #698)
Exclude password hash from the user object returned in login endpoint response. This prevents credential leaks where sensitive password hashes could be extracted and potentially subjected to offline attacks. Changes: - Extract user object and remove password field before returning - Ensure login response contains only non-sensitive user properties - Prevents password hash exposure in JSON responses Fixes #698
1 parent 53f820b commit 434bed1

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

backend/routes/auth.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ router.post("/signup", validateRequest(signupSchema), async (req, res) => {
3232

3333
// Login route
3434
router.post("/login", validateRequest(loginSchema), passport.authenticate('local'), (req, res) => {
35-
res.status(200).json( { message: 'Login successful', user: req.user } );
35+
const userObj = req.user.toObject ? req.user.toObject() : req.user;
36+
const { password, ...safeUser } = userObj;
37+
res.status(200).json( { message: 'Login successful', user: safeUser } );
3638
});
3739

3840
// Logout route

0 commit comments

Comments
 (0)