aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/validators/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares/validators/users.ts')
-rw-r--r--server/middlewares/validators/users.ts131
1 files changed, 85 insertions, 46 deletions
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 6d306121e..c3a07fccd 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -38,7 +38,7 @@ const usersListValidator = [
38 query('blocked') 38 query('blocked')
39 .optional() 39 .optional()
40 .customSanitizer(toBooleanOrNull) 40 .customSanitizer(toBooleanOrNull)
41 .isBoolean().withMessage('Should be a valid boolean banned state'), 41 .isBoolean().withMessage('Should be a valid blocked boolena'),
42 42
43 (req: express.Request, res: express.Response, next: express.NextFunction) => { 43 (req: express.Request, res: express.Response, next: express.NextFunction) => {
44 logger.debug('Checking usersList parameters', { parameters: req.query }) 44 logger.debug('Checking usersList parameters', { parameters: req.query })
@@ -50,19 +50,30 @@ const usersListValidator = [
50] 50]
51 51
52const usersAddValidator = [ 52const usersAddValidator = [
53 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), 53 body('username')
54 body('password').custom(isUserPasswordValidOrEmpty).withMessage('Should have a valid password'), 54 .custom(isUserUsernameValid)
55 body('email').isEmail().withMessage('Should have a valid email'), 55 .withMessage('Should have a valid username (lowercase alphanumeric characters)'),
56 body('password')
57 .custom(isUserPasswordValidOrEmpty),
58 body('email')
59 .isEmail(),
56 60
57 body('channelName').optional().custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), 61 body('channelName')
62 .optional()
63 .custom(isVideoChannelUsernameValid),
58 64
59 body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), 65 body('videoQuota')
60 body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), 66 .custom(isUserVideoQuotaValid),
67 body('videoQuotaDaily')
68 .custom(isUserVideoQuotaDailyValid),
61 69
62 body('role') 70 body('role')
63 .customSanitizer(toIntOrNull) 71 .customSanitizer(toIntOrNull)
64 .custom(isUserRoleValid).withMessage('Should have a valid role'), 72 .custom(isUserRoleValid),
65 body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), 73
74 body('adminFlags')
75 .optional()
76 .custom(isUserAdminFlagsValid),
66 77
67 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 78 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
68 logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') }) 79 logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') })
@@ -97,19 +108,22 @@ const usersAddValidator = [
97] 108]
98 109
99const usersRegisterValidator = [ 110const usersRegisterValidator = [
100 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username'), 111 body('username')
101 body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'), 112 .custom(isUserUsernameValid),
102 body('email').isEmail().withMessage('Should have a valid email'), 113 body('password')
114 .custom(isUserPasswordValid),
115 body('email')
116 .isEmail(),
103 body('displayName') 117 body('displayName')
104 .optional() 118 .optional()
105 .custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), 119 .custom(isUserDisplayNameValid),
106 120
107 body('channel.name') 121 body('channel.name')
108 .optional() 122 .optional()
109 .custom(isVideoChannelUsernameValid).withMessage('Should have a valid channel name'), 123 .custom(isVideoChannelUsernameValid),
110 body('channel.displayName') 124 body('channel.displayName')
111 .optional() 125 .optional()
112 .custom(isVideoChannelDisplayNameValid).withMessage('Should have a valid display name'), 126 .custom(isVideoChannelDisplayNameValid),
113 127
114 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 128 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
115 logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') }) 129 logger.debug('Checking usersRegister parameters', { parameters: omit(req.body, 'password') })
@@ -141,7 +155,8 @@ const usersRegisterValidator = [
141] 155]
142 156
143const usersRemoveValidator = [ 157const usersRemoveValidator = [
144 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 158 param('id')
159 .custom(isIdValid),
145 160
146 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 161 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
147 logger.debug('Checking usersRemove parameters', { parameters: req.params }) 162 logger.debug('Checking usersRemove parameters', { parameters: req.params })
@@ -159,8 +174,11 @@ const usersRemoveValidator = [
159] 174]
160 175
161const usersBlockingValidator = [ 176const usersBlockingValidator = [
162 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 177 param('id')
163 body('reason').optional().custom(isUserBlockedReasonValid).withMessage('Should have a valid blocking reason'), 178 .custom(isIdValid),
179 body('reason')
180 .optional()
181 .custom(isUserBlockedReasonValid),
164 182
165 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 183 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
166 logger.debug('Checking usersBlocking parameters', { parameters: req.params }) 184 logger.debug('Checking usersBlocking parameters', { parameters: req.params })
@@ -189,19 +207,33 @@ const deleteMeValidator = [
189] 207]
190 208
191const usersUpdateValidator = [ 209const usersUpdateValidator = [
192 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 210 param('id').custom(isIdValid),
193 211
194 body('password').optional().custom(isUserPasswordValid).withMessage('Should have a valid password'), 212 body('password')
195 body('email').optional().isEmail().withMessage('Should have a valid email attribute'), 213 .optional()
196 body('emailVerified').optional().isBoolean().withMessage('Should have a valid email verified attribute'), 214 .custom(isUserPasswordValid),
197 body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'), 215 body('email')
198 body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'), 216 .optional()
199 body('pluginAuth').optional(), 217 .isEmail(),
218 body('emailVerified')
219 .optional()
220 .isBoolean(),
221 body('videoQuota')
222 .optional()
223 .custom(isUserVideoQuotaValid),
224 body('videoQuotaDaily')
225 .optional()
226 .custom(isUserVideoQuotaDailyValid),
227 body('pluginAuth')
228 .optional()
229 .exists(),
200 body('role') 230 body('role')
201 .optional() 231 .optional()
202 .customSanitizer(toIntOrNull) 232 .customSanitizer(toIntOrNull)
203 .custom(isUserRoleValid).withMessage('Should have a valid role'), 233 .custom(isUserRoleValid),
204 body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'), 234 body('adminFlags')
235 .optional()
236 .custom(isUserAdminFlagsValid),
205 237
206 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 238 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
207 logger.debug('Checking usersUpdate parameters', { parameters: req.body }) 239 logger.debug('Checking usersUpdate parameters', { parameters: req.body })
@@ -221,37 +253,37 @@ const usersUpdateValidator = [
221const usersUpdateMeValidator = [ 253const usersUpdateMeValidator = [
222 body('displayName') 254 body('displayName')
223 .optional() 255 .optional()
224 .custom(isUserDisplayNameValid).withMessage('Should have a valid display name'), 256 .custom(isUserDisplayNameValid),
225 body('description') 257 body('description')
226 .optional() 258 .optional()
227 .custom(isUserDescriptionValid).withMessage('Should have a valid description'), 259 .custom(isUserDescriptionValid),
228 body('currentPassword') 260 body('currentPassword')
229 .optional() 261 .optional()
230 .custom(isUserPasswordValid).withMessage('Should have a valid current password'), 262 .custom(isUserPasswordValid),
231 body('password') 263 body('password')
232 .optional() 264 .optional()
233 .custom(isUserPasswordValid).withMessage('Should have a valid password'), 265 .custom(isUserPasswordValid),
234 body('email') 266 body('email')
235 .optional() 267 .optional()
236 .isEmail().withMessage('Should have a valid email attribute'), 268 .isEmail(),
237 body('nsfwPolicy') 269 body('nsfwPolicy')
238 .optional() 270 .optional()
239 .custom(isUserNSFWPolicyValid).withMessage('Should have a valid display Not Safe For Work policy'), 271 .custom(isUserNSFWPolicyValid),
240 body('autoPlayVideo') 272 body('autoPlayVideo')
241 .optional() 273 .optional()
242 .custom(isUserAutoPlayVideoValid).withMessage('Should have a valid automatically plays video attribute'), 274 .custom(isUserAutoPlayVideoValid),
243 body('p2pEnabled') 275 body('p2pEnabled')
244 .optional() 276 .optional()
245 .custom(isUserP2PEnabledValid).withMessage('Should have a valid p2p enabled boolean'), 277 .custom(isUserP2PEnabledValid).withMessage('Should have a valid p2p enabled boolean'),
246 body('videoLanguages') 278 body('videoLanguages')
247 .optional() 279 .optional()
248 .custom(isUserVideoLanguages).withMessage('Should have a valid video languages attribute'), 280 .custom(isUserVideoLanguages),
249 body('videosHistoryEnabled') 281 body('videosHistoryEnabled')
250 .optional() 282 .optional()
251 .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), 283 .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled boolean'),
252 body('theme') 284 body('theme')
253 .optional() 285 .optional()
254 .custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'), 286 .custom(v => isThemeNameValid(v) && isThemeRegistered(v)),
255 287
256 body('noInstanceConfigWarningModal') 288 body('noInstanceConfigWarningModal')
257 .optional() 289 .optional()
@@ -296,8 +328,11 @@ const usersUpdateMeValidator = [
296] 328]
297 329
298const usersGetValidator = [ 330const usersGetValidator = [
299 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 331 param('id')
300 query('withStats').optional().isBoolean().withMessage('Should have a valid stats flag'), 332 .custom(isIdValid),
333 query('withStats')
334 .optional()
335 .isBoolean().withMessage('Should have a valid withStats boolean'),
301 336
302 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 337 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
303 logger.debug('Checking usersGet parameters', { parameters: req.params }) 338 logger.debug('Checking usersGet parameters', { parameters: req.params })
@@ -326,12 +361,12 @@ const usersVideosValidator = [
326 query('isLive') 361 query('isLive')
327 .optional() 362 .optional()
328 .customSanitizer(toBooleanOrNull) 363 .customSanitizer(toBooleanOrNull)
329 .custom(isBooleanValid).withMessage('Should have a valid live boolean'), 364 .custom(isBooleanValid).withMessage('Should have a valid isLive boolean'),
330 365
331 query('channelId') 366 query('channelId')
332 .optional() 367 .optional()
333 .customSanitizer(toIntOrNull) 368 .customSanitizer(toIntOrNull)
334 .custom(isIdValid).withMessage('Should have a valid channel id'), 369 .custom(isIdValid),
335 370
336 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 371 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
337 logger.debug('Checking usersVideosValidator parameters', { parameters: req.query }) 372 logger.debug('Checking usersVideosValidator parameters', { parameters: req.query })
@@ -384,7 +419,8 @@ const ensureUserRegistrationAllowedForIP = [
384] 419]
385 420
386const usersAskResetPasswordValidator = [ 421const usersAskResetPasswordValidator = [
387 body('email').isEmail().not().isEmpty().withMessage('Should have a valid email'), 422 body('email')
423 .isEmail(),
388 424
389 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 425 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
390 logger.debug('Checking usersAskResetPassword parameters', { parameters: req.body }) 426 logger.debug('Checking usersAskResetPassword parameters', { parameters: req.body })
@@ -403,9 +439,12 @@ const usersAskResetPasswordValidator = [
403] 439]
404 440
405const usersResetPasswordValidator = [ 441const usersResetPasswordValidator = [
406 param('id').isInt().not().isEmpty().withMessage('Should have a valid id'), 442 param('id')
407 body('verificationString').not().isEmpty().withMessage('Should have a valid verification string'), 443 .custom(isIdValid),
408 body('password').custom(isUserPasswordValid).withMessage('Should have a valid password'), 444 body('verificationString')
445 .not().isEmpty(),
446 body('password')
447 .custom(isUserPasswordValid),
409 448
410 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 449 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
411 logger.debug('Checking usersResetPassword parameters', { parameters: req.params }) 450 logger.debug('Checking usersResetPassword parameters', { parameters: req.params })