Skip to content

Commit 9b27e84

Browse files
committed
fix: add input validation for check_type in duplicate check
1 parent bfe708c commit 9b27e84

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

server/controllers/user.controller/signup.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,29 @@ 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+
// Validate check_type to prevent prototype pollution
102+
if (
103+
!checkType ||
104+
!allowedCheckTypes.includes(checkType as 'email' | 'username')
105+
) {
106+
return res.status(400).json({
107+
error: 'Invalid check_type. Must be either "email" or "username".'
108+
});
109+
}
110+
99111
const value = req.query[checkType];
112+
113+
// Validate that the corresponding value exists
114+
if (!value || typeof value !== 'string' || value.trim().length === 0) {
115+
return res.status(400).json({
116+
error: `Missing or invalid ${checkType} value.`
117+
});
118+
}
119+
100120
const options = { caseInsensitive: true, valueType: checkType };
101-
const user = await User.findByEmailOrUsername(value!, options);
121+
const user = await User.findByEmailOrUsername(value, options);
102122
if (user) {
103123
return res.json({
104124
exists: true,

0 commit comments

Comments
 (0)