Skip to content

Commit

Permalink
chore: dont leak password in auth requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhiteley committed Oct 6, 2024
1 parent 52c2109 commit dda2f5b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/service/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ router.get('/', (req, res) => {

router.post('/login', passport.authenticate(passportType), async (req, res) => {
try {
const currentUser = { ...req.user };
delete currentUser.password;
console.log(
`serivce.routes.auth.login: user logged in, username=${
req.user.username
} profile=${JSON.stringify(req.user)}`,
currentUser.username
} profile=${JSON.stringify(currentUser)}`,
);
res.send({
message: 'success',
user: currentUser,
});
} catch (e) {
console.log(`service.routes.auth.login: Error logging user in ${JSON.stringify(e)}`);
res.status(500).send('Failed to login').end();
return;
}
res.send({
message: 'success',
user: req.user,
});
});

// when login is successful, retrieve user info
Expand Down Expand Up @@ -115,6 +117,7 @@ router.get('/userLoggedIn', async (req, res) => {
delete user.password;
const login = user.username;
const userVal = await db.findUser(login);
delete userVal.password;

Check warning on line 120 in src/service/routes/auth.js

View check run for this annotation

Codecov / codecov/patch

src/service/routes/auth.js#L120

Added line #L120 was not covered by tests
res.send(userVal);
} else {
res.status(401).end();
Expand Down

0 comments on commit dda2f5b

Please sign in to comment.