Skip to content

Commit 3363148

Browse files
authored
Merge pull request #3967 from Nixxx19/nityam/fix-duplicate-check-validation
fix: add input validation for check_type in duplicate check
2 parents 022fdd4 + 86fd49d commit 3363148

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

server/controllers/user.controller/signup.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,27 @@ export const duplicateUserCheck: RequestHandler<
9696
DuplicateUserCheckQuery
9797
> = async (req, res) => {
9898
const checkType = req.query.check_type;
99+
const allowedCheckTypes = ['email', 'username'] as const;
100+
101+
if (
102+
!checkType ||
103+
!allowedCheckTypes.includes(checkType as 'email' | 'username')
104+
) {
105+
return res.status(400).json({
106+
error: 'Invalid check_type. Must be either "email" or "username".'
107+
});
108+
}
109+
99110
const value = req.query[checkType];
111+
112+
if (!value || typeof value !== 'string' || value.trim().length === 0) {
113+
return res.status(400).json({
114+
error: `Missing or invalid ${checkType} value.`
115+
});
116+
}
117+
100118
const options = { caseInsensitive: true, valueType: checkType };
101-
const user = await User.findByEmailOrUsername(value!, options);
119+
const user = await User.findByEmailOrUsername(value, options);
102120
if (user) {
103121
return res.json({
104122
exists: true,

0 commit comments

Comments
 (0)