Skip to content

Commit 6008907

Browse files
jeetclaude
andcommitted
fix(security): strip passwordHash from login responses, add invite TTL, add registration guard
- delete result.user.passwordHash before res.json in parent and kid login handlers - add ALLOW_REGISTRATION=false env guard to /auth/register - validateInvite now rejects codes older than 48h Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent b0d6294 commit 6008907

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/server/modules/auth/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ authRouter.post('/auth/register', authLimiter, [
6565
body('name').isString().notEmpty(),
6666
validate
6767
], async (req: Request, res: Response) => {
68+
if (process.env.ALLOW_REGISTRATION === 'false') {
69+
return res.status(403).json({ error: 'Registration is disabled' });
70+
}
6871
try {
6972
const result = await authService.register(req.body.email, req.body.password, req.body.name);
7073
return res.json(result);
@@ -94,6 +97,7 @@ authRouter.post('/auth/login', authLimiter, [
9497
}
9598
clearAuthFailure(key);
9699
result.user.badges = JSON.parse(result.user.badges || "[]");
100+
delete result.user.passwordHash;
97101
logSecurityEvent('auth.parent_login.success', { uid: result.user.uid, ip }, 'info');
98102
return res.json(result);
99103
});
@@ -119,6 +123,7 @@ authRouter.post('/auth/login/kid', authLimiter, [
119123
}
120124
clearAuthFailure(key);
121125
result.user.badges = JSON.parse(result.user.badges || "[]");
126+
delete result.user.passwordHash;
122127
logSecurityEvent('auth.kid_login.success', { uid: result.user.uid, ip }, 'info');
123128
return res.json(result);
124129
});

src/server/modules/invites/service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export const inviteService = {
1818
},
1919

2020
validateInvite: (code: string) => {
21-
return db.prepare("SELECT * FROM invites WHERE id = ? AND status = 'active'").get(code);
21+
const ttlMs = 48 * 60 * 60 * 1000;
22+
return db.prepare("SELECT * FROM invites WHERE id = ? AND status = 'active' AND createdAt > ?").get(code, Date.now() - ttlMs);
2223
},
2324

2425
markInviteUsed: (code: string) => {

0 commit comments

Comments
 (0)