File tree Expand file tree Collapse file tree
server/controllers/user.controller Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments