aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-25 16:23:44 +0200
committerChocobozzz <me@florianbigard.com>2019-07-25 16:23:44 +0200
commitc8861d5dc0436ef4342ce517241e3591fa256a13 (patch)
treeca47c09d1f7f1e2aa62c684d576faa938eb47af7 /server/middlewares
parentb4c19345c19b0891142c69308cd9447f2161188c (diff)
downloadPeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.gz
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.tar.zst
PeerTube-c8861d5dc0436ef4342ce517241e3591fa256a13.zip
Fix express validator
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/oauth.ts1
-rw-r--r--server/middlewares/pagination.ts2
-rw-r--r--server/middlewares/servers.ts1
-rw-r--r--server/middlewares/sort.ts1
-rw-r--r--server/middlewares/user-right.ts1
-rw-r--r--server/middlewares/validators/account.ts2
-rw-r--r--server/middlewares/validators/activitypub/signature.ts2
-rw-r--r--server/middlewares/validators/avatar.ts2
-rw-r--r--server/middlewares/validators/blocklist.ts2
-rw-r--r--server/middlewares/validators/config.ts2
-rw-r--r--server/middlewares/validators/feeds.ts2
-rw-r--r--server/middlewares/validators/follows.ts2
-rw-r--r--server/middlewares/validators/jobs.ts2
-rw-r--r--server/middlewares/validators/logs.ts2
-rw-r--r--server/middlewares/validators/oembed.ts2
-rw-r--r--server/middlewares/validators/pagination.ts2
-rw-r--r--server/middlewares/validators/plugins.ts6
-rw-r--r--server/middlewares/validators/redundancy.ts7
-rw-r--r--server/middlewares/validators/search.ts2
-rw-r--r--server/middlewares/validators/server.ts2
-rw-r--r--server/middlewares/validators/themes.ts2
-rw-r--r--server/middlewares/validators/user-history.ts3
-rw-r--r--server/middlewares/validators/user-notifications.ts7
-rw-r--r--server/middlewares/validators/user-subscriptions.ts3
-rw-r--r--server/middlewares/validators/users.ts7
-rw-r--r--server/middlewares/validators/utils.ts2
-rw-r--r--server/middlewares/validators/videos/video-abuses.ts3
-rw-r--r--server/middlewares/validators/videos/video-blacklist.ts6
-rw-r--r--server/middlewares/validators/videos/video-captions.ts2
-rw-r--r--server/middlewares/validators/videos/video-channels.ts2
-rw-r--r--server/middlewares/validators/videos/video-comments.ts2
-rw-r--r--server/middlewares/validators/videos/video-imports.ts6
-rw-r--r--server/middlewares/validators/videos/video-playlists.ts17
-rw-r--r--server/middlewares/validators/videos/video-rates.ts3
-rw-r--r--server/middlewares/validators/videos/video-shares.ts3
-rw-r--r--server/middlewares/validators/videos/video-watch.ts6
-rw-r--r--server/middlewares/validators/videos/videos.ts26
-rw-r--r--server/middlewares/validators/webfinger.ts2
38 files changed, 70 insertions, 77 deletions
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 2b4e300e4..77fb305dd 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as OAuthServer from 'express-oauth-server' 2import * as OAuthServer from 'express-oauth-server'
3import 'express-validator'
4import { OAUTH_LIFETIME } from '../initializers/constants' 3import { OAUTH_LIFETIME } from '../initializers/constants'
5import { logger } from '../helpers/logger' 4import { logger } from '../helpers/logger'
6import { Socket } from 'socket.io' 5import { Socket } from 'socket.io'
diff --git a/server/middlewares/pagination.ts b/server/middlewares/pagination.ts
index 83304940f..043869303 100644
--- a/server/middlewares/pagination.ts
+++ b/server/middlewares/pagination.ts
@@ -1,6 +1,4 @@
1import 'express-validator'
2import * as express from 'express' 1import * as express from 'express'
3
4import { PAGINATION } from '../initializers/constants' 2import { PAGINATION } from '../initializers/constants'
5 3
6function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) { 4function setDefaultPagination (req: express.Request, res: express.Response, next: express.NextFunction) {
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts
index c52f4685b..9c0af443a 100644
--- a/server/middlewares/servers.ts
+++ b/server/middlewares/servers.ts
@@ -1,5 +1,4 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator'
3import { getHostWithPort } from '../helpers/express-utils' 2import { getHostWithPort } from '../helpers/express-utils'
4 3
5function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { 4function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index 6507aa5b8..8c27e8237 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -1,5 +1,4 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator'
3import { SortType } from '../models/utils' 2import { SortType } from '../models/utils'
4 3
5function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) { 4function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts
index 498e3d677..4da7b9802 100644
--- a/server/middlewares/user-right.ts
+++ b/server/middlewares/user-right.ts
@@ -1,5 +1,4 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator'
3import { UserRight } from '../../shared' 2import { UserRight } from '../../shared'
4import { logger } from '../helpers/logger' 3import { logger } from '../helpers/logger'
5 4
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 67e4bf8cc..cbdcef2fd 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator'
3import { isAccountNameValid } from '../../helpers/custom-validators/accounts' 3import { isAccountNameValid } from '../../helpers/custom-validators/accounts'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts
index be14e92ea..02b191480 100644
--- a/server/middlewares/validators/activitypub/signature.ts
+++ b/server/middlewares/validators/activitypub/signature.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator'
3import { 3import {
4 isSignatureCreatorValid, isSignatureTypeValid, 4 isSignatureCreatorValid, isSignatureTypeValid,
5 isSignatureValueValid 5 isSignatureValueValid
diff --git a/server/middlewares/validators/avatar.ts b/server/middlewares/validators/avatar.ts
index bab3ed118..8623d07e8 100644
--- a/server/middlewares/validators/avatar.ts
+++ b/server/middlewares/validators/avatar.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator'
3import { isAvatarFile } from '../../helpers/custom-validators/users' 3import { isAvatarFile } from '../../helpers/custom-validators/users'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 5import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts
index 63d95e9e0..47a0b1a1c 100644
--- a/server/middlewares/validators/blocklist.ts
+++ b/server/middlewares/validators/blocklist.ts
@@ -1,4 +1,4 @@
1import { body, param } from 'express-validator/check' 1import { body, param } from 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index 9c43da165..5059ed0f2 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator'
3import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users' 3import { isUserNSFWPolicyValid, isUserVideoQuotaDailyValid, isUserVideoQuotaValid } from '../../helpers/custom-validators/users'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts
index fa130121f..1bef9891b 100644
--- a/server/middlewares/validators/feeds.ts
+++ b/server/middlewares/validators/feeds.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param, query } from 'express-validator/check' 2import { param, query } from 'express-validator'
3import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 2e5a02307..c3d772297 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator'
3import { isTestInstance } from '../../helpers/core-utils' 3import { isTestInstance } from '../../helpers/core-utils'
4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' 4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
diff --git a/server/middlewares/validators/jobs.ts b/server/middlewares/validators/jobs.ts
index 2f8b1738c..41a8d6899 100644
--- a/server/middlewares/validators/jobs.ts
+++ b/server/middlewares/validators/jobs.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator'
3import { isValidJobState } from '../../helpers/custom-validators/jobs' 3import { isValidJobState } from '../../helpers/custom-validators/jobs'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts
index 7380c6edd..07f3f552f 100644
--- a/server/middlewares/validators/logs.ts
+++ b/server/middlewares/validators/logs.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import { logger } from '../../helpers/logger' 2import { logger } from '../../helpers/logger'
3import { areValidationErrors } from './utils' 3import { areValidationErrors } from './utils'
4import { isDateValid } from '../../helpers/custom-validators/misc' 4import { isDateValid } from '../../helpers/custom-validators/misc'
5import { query } from 'express-validator/check' 5import { query } from 'express-validator'
6import { isValidLogLevel } from '../../helpers/custom-validators/logs' 6import { isValidLogLevel } from '../../helpers/custom-validators/logs'
7 7
8const getLogsValidator = [ 8const getLogsValidator = [
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index 505319980..24ba5569d 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator'
3import { join } from 'path' 3import { join } from 'path'
4import { isTestInstance } from '../../helpers/core-utils' 4import { isTestInstance } from '../../helpers/core-utils'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts
index e1ed8cd65..80ae57c0b 100644
--- a/server/middlewares/validators/pagination.ts
+++ b/server/middlewares/validators/pagination.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5 5
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index dc3f1454a..910d03c29 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -1,10 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator/check' 2import { body, param, query } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' 5import { isNpmPluginNameValid, isPluginNameValid, isPluginTypeValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
6import { PluginManager } from '../../lib/plugins/plugin-manager' 6import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' 7import { isBooleanValid, isSafePath, toBooleanOrNull } from '../../helpers/custom-validators/misc'
8import { PluginModel } from '../../models/server/plugin' 8import { PluginModel } from '../../models/server/plugin'
9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model' 9import { InstallOrUpdatePlugin } from '../../../shared/models/plugins/install-plugin.model'
10import { PluginType } from '../../../shared/models/plugins/plugin.type' 10import { PluginType } from '../../../shared/models/plugins/plugin.type'
@@ -39,7 +39,7 @@ const listPluginsValidator = [
39 .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'), 39 .custom(isPluginTypeValid).withMessage('Should have a valid plugin type'),
40 query('uninstalled') 40 query('uninstalled')
41 .optional() 41 .optional()
42 .toBoolean() 42 .customSanitizer(toBooleanOrNull)
43 .custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'), 43 .custom(isBooleanValid).withMessage('Should have a valid uninstalled attribute'),
44 44
45 (req: express.Request, res: express.Response, next: express.NextFunction) => { 45 (req: express.Request, res: express.Response, next: express.NextFunction) => {
diff --git a/server/middlewares/validators/redundancy.ts b/server/middlewares/validators/redundancy.ts
index edc53a6b2..1fdac0e4e 100644
--- a/server/middlewares/validators/redundancy.ts
+++ b/server/middlewares/validators/redundancy.ts
@@ -1,7 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param } from 'express-validator'
3import { body, param } from 'express-validator/check' 3import { exists, isBooleanValid, isIdOrUUIDValid, toBooleanOrNull, toIntOrNull } from '../../helpers/custom-validators/misc'
4import { exists, isBooleanValid, isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
5import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
6import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
7import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' 6import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
@@ -68,7 +67,7 @@ const videoPlaylistRedundancyGetValidator = [
68const updateServerRedundancyValidator = [ 67const updateServerRedundancyValidator = [
69 param('host').custom(isHostValid).withMessage('Should have a valid host'), 68 param('host').custom(isHostValid).withMessage('Should have a valid host'),
70 body('redundancyAllowed') 69 body('redundancyAllowed')
71 .toBoolean() 70 .customSanitizer(toBooleanOrNull)
72 .custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'), 71 .custom(isBooleanValid).withMessage('Should have a valid redundancyAllowed attribute'),
73 72
74 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 73 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts
index 7816d229c..5a3c83f2c 100644
--- a/server/middlewares/validators/search.ts
+++ b/server/middlewares/validators/search.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from './utils' 2import { areValidationErrors } from './utils'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { query } from 'express-validator/check' 4import { query } from 'express-validator'
5import { isDateValid } from '../../helpers/custom-validators/misc' 5import { isDateValid } from '../../helpers/custom-validators/misc'
6 6
7const videosSearchValidator = [ 7const videosSearchValidator = [
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts
index 6eff8e9ee..f6812647b 100644
--- a/server/middlewares/validators/server.ts
+++ b/server/middlewares/validators/server.ts
@@ -3,7 +3,7 @@ import { logger } from '../../helpers/logger'
3import { areValidationErrors } from './utils' 3import { areValidationErrors } from './utils'
4import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers' 4import { isHostValid, isValidContactBody } from '../../helpers/custom-validators/servers'
5import { ServerModel } from '../../models/server/server' 5import { ServerModel } from '../../models/server/server'
6import { body } from 'express-validator/check' 6import { body } from 'express-validator'
7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' 7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
8import { Emailer } from '../../lib/emailer' 8import { Emailer } from '../../lib/emailer'
9import { Redis } from '../../lib/redis' 9import { Redis } from '../../lib/redis'
diff --git a/server/middlewares/validators/themes.ts b/server/middlewares/validators/themes.ts
index 642f2df78..24a9673f7 100644
--- a/server/middlewares/validators/themes.ts
+++ b/server/middlewares/validators/themes.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins' 5import { isPluginNameValid, isPluginVersionValid } from '../../helpers/custom-validators/plugins'
diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts
index 418313d09..2f1d3cc41 100644
--- a/server/middlewares/validators/user-history.ts
+++ b/server/middlewares/validators/user-history.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body } from 'express-validator'
3import { body } from 'express-validator/check'
4import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
6import { isDateValid } from '../../helpers/custom-validators/misc' 5import { isDateValid } from '../../helpers/custom-validators/misc'
diff --git a/server/middlewares/validators/user-notifications.ts b/server/middlewares/validators/user-notifications.ts
index 3ded8d8cf..308b32655 100644
--- a/server/middlewares/validators/user-notifications.ts
+++ b/server/middlewares/validators/user-notifications.ts
@@ -1,15 +1,14 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, query } from 'express-validator'
3import { body, query } from 'express-validator/check'
4import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
6import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications' 5import { isUserNotificationSettingValid } from '../../helpers/custom-validators/user-notifications'
7import { isNotEmptyIntArray } from '../../helpers/custom-validators/misc' 6import { isNotEmptyIntArray, toBooleanOrNull } from '../../helpers/custom-validators/misc'
8 7
9const listUserNotificationsValidator = [ 8const listUserNotificationsValidator = [
10 query('unread') 9 query('unread')
11 .optional() 10 .optional()
12 .toBoolean() 11 .customSanitizer(toBooleanOrNull)
13 .isBoolean().withMessage('Should have a valid unread boolean'), 12 .isBoolean().withMessage('Should have a valid unread boolean'),
14 13
15 (req: express.Request, res: express.Response, next: express.NextFunction) => { 14 (req: express.Request, res: express.Response, next: express.NextFunction) => {
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts
index 2356745d7..9bc8c87e7 100644
--- a/server/middlewares/validators/user-subscriptions.ts
+++ b/server/middlewares/validators/user-subscriptions.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param, query } from 'express-validator'
3import { body, param, query } from 'express-validator/check'
4import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
6import { ActorFollowModel } from '../../models/activitypub/actor-follow' 5import { ActorFollowModel } from '../../models/activitypub/actor-follow'
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index 7002de20d..db03dc231 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -1,9 +1,8 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import * as express from 'express' 2import * as express from 'express'
3import 'express-validator' 3import { body, param } from 'express-validator'
4import { body, param } from 'express-validator/check'
5import { omit } from 'lodash' 4import { omit } from 'lodash'
6import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid, toIntOrNull } from '../../helpers/custom-validators/misc'
7import { 6import {
8 isUserAdminFlagsValid, 7 isUserAdminFlagsValid,
9 isUserAutoPlayVideoValid, 8 isUserAutoPlayVideoValid,
@@ -358,7 +357,7 @@ const usersVerifyEmailValidator = [
358 .not().isEmpty().withMessage('Should have a valid verification string'), 357 .not().isEmpty().withMessage('Should have a valid verification string'),
359 body('isPendingEmail') 358 body('isPendingEmail')
360 .optional() 359 .optional()
361 .toBoolean(), 360 .customSanitizer(toIntOrNull),
362 361
363 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 362 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
364 logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params }) 363 logger.debug('Checking usersVerifyEmail parameters', { parameters: req.params })
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts
index 8f77c9fbd..43e5652fa 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/utils.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query, validationResult } from 'express-validator/check' 2import { query, validationResult } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4 4
5function areValidationErrors (req: express.Request, res: express.Response) { 5function areValidationErrors (req: express.Request, res: express.Response) {
diff --git a/server/middlewares/validators/videos/video-abuses.ts b/server/middlewares/validators/videos/video-abuses.ts
index e176e01af..e27d91bb1 100644
--- a/server/middlewares/validators/videos/video-abuses.ts
+++ b/server/middlewares/validators/videos/video-abuses.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param } from 'express-validator'
3import { body, param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
diff --git a/server/middlewares/validators/videos/video-blacklist.ts b/server/middlewares/validators/videos/video-blacklist.ts
index db59427c7..3e8c5b30c 100644
--- a/server/middlewares/validators/videos/video-blacklist.ts
+++ b/server/middlewares/validators/videos/video-blacklist.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query } from 'express-validator/check' 2import { body, param, query } from 'express-validator'
3import { isBooleanValid, isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isBooleanValid, isIdOrUUIDValid, toBooleanOrNull } from '../../../helpers/custom-validators/misc'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist' 6import { isVideoBlacklistReasonValid, isVideoBlacklistTypeValid } from '../../../helpers/custom-validators/video-blacklist'
@@ -24,7 +24,7 @@ const videosBlacklistAddValidator = [
24 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'), 24 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
25 body('unfederate') 25 body('unfederate')
26 .optional() 26 .optional()
27 .toBoolean() 27 .customSanitizer(toBooleanOrNull)
28 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'), 28 .custom(isBooleanValid).withMessage('Should have a valid unfederate boolean'),
29 body('reason') 29 body('reason')
30 .optional() 30 .optional()
diff --git a/server/middlewares/validators/videos/video-captions.ts b/server/middlewares/validators/videos/video-captions.ts
index f8739e27f..f5610222a 100644
--- a/server/middlewares/validators/videos/video-captions.ts
+++ b/server/middlewares/validators/videos/video-captions.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { areValidationErrors } from '../utils' 2import { areValidationErrors } from '../utils'
3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
4import { body, param } from 'express-validator/check' 4import { body, param } from 'express-validator'
5import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 5import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
6import { UserRight } from '../../../../shared' 6import { UserRight } from '../../../../shared'
7import { logger } from '../../../helpers/logger' 7import { logger } from '../../../helpers/logger'
diff --git a/server/middlewares/validators/videos/video-channels.ts b/server/middlewares/validators/videos/video-channels.ts
index c1065b898..3ee5064fc 100644
--- a/server/middlewares/validators/videos/video-channels.ts
+++ b/server/middlewares/validators/videos/video-channels.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator'
3import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { 4import {
5 isVideoChannelDescriptionValid, 5 isVideoChannelDescriptionValid,
diff --git a/server/middlewares/validators/videos/video-comments.ts b/server/middlewares/validators/videos/video-comments.ts
index 1e3e42833..83a0c24b0 100644
--- a/server/middlewares/validators/videos/video-comments.ts
+++ b/server/middlewares/validators/videos/video-comments.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator'
3import { UserRight } from '../../../../shared' 3import { UserRight } from '../../../../shared'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments' 5import { isValidVideoCommentText } from '../../../helpers/custom-validators/video-comments'
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index 8b0dd8960..318dad100 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator'
3import { isIdValid } from '../../../helpers/custom-validators/misc' 3import { isIdValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6import { getCommonVideoEditAttributes } from './videos' 6import { getCommonVideoEditAttributes } from './videos'
@@ -13,7 +13,7 @@ import { doesVideoChannelOfAccountExist } from '../../../helpers/middlewares'
13 13
14const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 14const videoImportAddValidator = getCommonVideoEditAttributes().concat([
15 body('channelId') 15 body('channelId')
16 .toInt() 16 .customSanitizer(toIntOrNull)
17 .custom(isIdValid).withMessage('Should have correct video channel id'), 17 .custom(isIdValid).withMessage('Should have correct video channel id'),
18 body('targetUrl') 18 body('targetUrl')
19 .optional() 19 .optional()
diff --git a/server/middlewares/validators/videos/video-playlists.ts b/server/middlewares/validators/videos/video-playlists.ts
index 638122a2e..2e9c8aa33 100644
--- a/server/middlewares/validators/videos/video-playlists.ts
+++ b/server/middlewares/validators/videos/video-playlists.ts
@@ -1,12 +1,20 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param, query, ValidationChain } from 'express-validator/check' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared' 3import { UserRight, VideoPlaylistCreate, VideoPlaylistUpdate } from '../../../../shared'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { UserModel } from '../../../models/account/user' 5import { UserModel } from '../../../models/account/user'
6import { areValidationErrors } from '../utils' 6import { areValidationErrors } from '../utils'
7import { isVideoImage } from '../../../helpers/custom-validators/videos' 7import { isVideoImage } from '../../../helpers/custom-validators/videos'
8import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' 8import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
9import { isArrayOf, isIdOrUUIDValid, isIdValid, isUUIDValid, toIntArray, toValueOrNull } from '../../../helpers/custom-validators/misc' 9import {
10 isArrayOf,
11 isIdOrUUIDValid,
12 isIdValid,
13 isUUIDValid,
14 toIntArray,
15 toIntOrNull,
16 toValueOrNull
17} from '../../../helpers/custom-validators/misc'
10import { 18import {
11 isVideoPlaylistDescriptionValid, 19 isVideoPlaylistDescriptionValid,
12 isVideoPlaylistNameValid, 20 isVideoPlaylistNameValid,
@@ -374,12 +382,11 @@ function getCommonPlaylistEditAttributes () {
374 .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'), 382 .custom(isVideoPlaylistDescriptionValid).withMessage('Should have a valid description'),
375 body('privacy') 383 body('privacy')
376 .optional() 384 .optional()
377 .toInt() 385 .customSanitizer(toIntOrNull)
378 .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'), 386 .custom(isVideoPlaylistPrivacyValid).withMessage('Should have correct playlist privacy'),
379 body('videoChannelId') 387 body('videoChannelId')
380 .optional() 388 .optional()
381 .customSanitizer(toValueOrNull) 389 .customSanitizer(toIntOrNull)
382 .toInt()
383 ] as (ValidationChain | express.Handler)[] 390 ] as (ValidationChain | express.Handler)[]
384} 391}
385 392
diff --git a/server/middlewares/validators/videos/video-rates.ts b/server/middlewares/validators/videos/video-rates.ts
index 5bb3f4a51..4021cfecc 100644
--- a/server/middlewares/validators/videos/video-rates.ts
+++ b/server/middlewares/validators/videos/video-rates.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param, query } from 'express-validator'
3import { body, param, query } from 'express-validator/check'
4import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc'
5import { isRatingValid } from '../../../helpers/custom-validators/video-rates' 4import { isRatingValid } from '../../../helpers/custom-validators/video-rates'
6import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos' 5import { isVideoRatingTypeValid } from '../../../helpers/custom-validators/videos'
diff --git a/server/middlewares/validators/videos/video-shares.ts b/server/middlewares/validators/videos/video-shares.ts
index 6f4a1f3e0..ace62be5c 100644
--- a/server/middlewares/validators/videos/video-shares.ts
+++ b/server/middlewares/validators/videos/video-shares.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { param } from 'express-validator'
3import { param } from 'express-validator/check'
4import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../../helpers/custom-validators/misc'
5import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
6import { VideoShareModel } from '../../../models/video/video-share' 5import { VideoShareModel } from '../../../models/video/video-share'
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts
index a0b530c75..d6ca1d341 100644
--- a/server/middlewares/validators/videos/video-watch.ts
+++ b/server/middlewares/validators/videos/video-watch.ts
@@ -1,6 +1,6 @@
1import { body, param } from 'express-validator/check' 1import { body, param } from 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, toIntOrNull } from '../../../helpers/custom-validators/misc'
4import { areValidationErrors } from '../utils' 4import { areValidationErrors } from '../utils'
5import { logger } from '../../../helpers/logger' 5import { logger } from '../../../helpers/logger'
6import { doesVideoExist } from '../../../helpers/middlewares' 6import { doesVideoExist } from '../../../helpers/middlewares'
@@ -8,7 +8,7 @@ import { doesVideoExist } from '../../../helpers/middlewares'
8const videoWatchingValidator = [ 8const videoWatchingValidator = [
9 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), 9 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'),
10 body('currentTime') 10 body('currentTime')
11 .toInt() 11 .customSanitizer(toIntOrNull)
12 .isInt().withMessage('Should have correct current time'), 12 .isInt().withMessage('Should have correct current time'),
13 13
14 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 14 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index 8f5e5c95c..27dfe91ca 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -1,6 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import { body, param, query, ValidationChain } from 'express-validator'
3import { body, param, query, ValidationChain } from 'express-validator/check'
4import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared' 3import { UserRight, VideoChangeOwnershipStatus, VideoPrivacy } from '../../../../shared'
5import { 4import {
6 isBooleanValid, 5 isBooleanValid,
@@ -9,6 +8,7 @@ import {
9 isIdValid, 8 isIdValid,
10 isUUIDValid, 9 isUUIDValid,
11 toArray, 10 toArray,
11 toBooleanOrNull,
12 toIntOrNull, 12 toIntOrNull,
13 toValueOrNull 13 toValueOrNull
14} from '../../../helpers/custom-validators/misc' 14} from '../../../helpers/custom-validators/misc'
@@ -53,7 +53,7 @@ const videosAddValidator = getCommonVideoEditAttributes().concat([
53 ), 53 ),
54 body('name').custom(isVideoNameValid).withMessage('Should have a valid name'), 54 body('name').custom(isVideoNameValid).withMessage('Should have a valid name'),
55 body('channelId') 55 body('channelId')
56 .toInt() 56 .customSanitizer(toIntOrNull)
57 .custom(isIdValid).withMessage('Should have correct video channel id'), 57 .custom(isIdValid).withMessage('Should have correct video channel id'),
58 58
59 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 59 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -101,7 +101,7 @@ const videosUpdateValidator = getCommonVideoEditAttributes().concat([
101 .custom(isVideoNameValid).withMessage('Should have a valid name'), 101 .custom(isVideoNameValid).withMessage('Should have a valid name'),
102 body('channelId') 102 body('channelId')
103 .optional() 103 .optional()
104 .toInt() 104 .customSanitizer(toIntOrNull)
105 .custom(isIdValid).withMessage('Should have correct video channel id'), 105 .custom(isIdValid).withMessage('Should have correct video channel id'),
106 106
107 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 107 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
@@ -307,15 +307,15 @@ function getCommonVideoEditAttributes () {
307 .custom(isVideoLanguageValid).withMessage('Should have a valid language'), 307 .custom(isVideoLanguageValid).withMessage('Should have a valid language'),
308 body('nsfw') 308 body('nsfw')
309 .optional() 309 .optional()
310 .toBoolean() 310 .customSanitizer(toBooleanOrNull)
311 .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'), 311 .custom(isBooleanValid).withMessage('Should have a valid NSFW attribute'),
312 body('waitTranscoding') 312 body('waitTranscoding')
313 .optional() 313 .optional()
314 .toBoolean() 314 .customSanitizer(toBooleanOrNull)
315 .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'), 315 .custom(isBooleanValid).withMessage('Should have a valid wait transcoding attribute'),
316 body('privacy') 316 body('privacy')
317 .optional() 317 .optional()
318 .toInt() 318 .customSanitizer(toValueOrNull)
319 .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'), 319 .custom(isVideoPrivacyValid).withMessage('Should have correct video privacy'),
320 body('description') 320 body('description')
321 .optional() 321 .optional()
@@ -331,16 +331,16 @@ function getCommonVideoEditAttributes () {
331 .custom(isVideoTagsValid).withMessage('Should have correct tags'), 331 .custom(isVideoTagsValid).withMessage('Should have correct tags'),
332 body('commentsEnabled') 332 body('commentsEnabled')
333 .optional() 333 .optional()
334 .toBoolean() 334 .customSanitizer(toBooleanOrNull)
335 .custom(isBooleanValid).withMessage('Should have comments enabled boolean'), 335 .custom(isBooleanValid).withMessage('Should have comments enabled boolean'),
336 body('downloadEnabled') 336 body('downloadEnabled')
337 .optional() 337 .optional()
338 .toBoolean() 338 .customSanitizer(toBooleanOrNull)
339 .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'), 339 .custom(isBooleanValid).withMessage('Should have downloading enabled boolean'),
340 body('originallyPublishedAt') 340 body('originallyPublishedAt')
341 .optional() 341 .optional()
342 .customSanitizer(toValueOrNull) 342 .customSanitizer(toValueOrNull)
343 .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'), 343 .custom(isVideoOriginallyPublishedAtValid).withMessage('Should have a valid original publication date'),
344 body('scheduleUpdate') 344 body('scheduleUpdate')
345 .optional() 345 .optional()
346 .customSanitizer(toValueOrNull), 346 .customSanitizer(toValueOrNull),
@@ -349,7 +349,7 @@ function getCommonVideoEditAttributes () {
349 .custom(isDateValid).withMessage('Should have a valid schedule update date'), 349 .custom(isDateValid).withMessage('Should have a valid schedule update date'),
350 body('scheduleUpdate.privacy') 350 body('scheduleUpdate.privacy')
351 .optional() 351 .optional()
352 .toInt() 352 .customSanitizer(toValueOrNull)
353 .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy') 353 .custom(isScheduleVideoUpdatePrivacyValid).withMessage('Should have correct schedule update privacy')
354 ] as (ValidationChain | express.Handler)[] 354 ] as (ValidationChain | express.Handler)[]
355} 355}
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 63a1678ec..d7cfe17f0 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator'
3import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger' 3import { isWebfingerLocalResourceValid } from '../../helpers/custom-validators/webfinger'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { ActorModel } from '../../models/activitypub/actor' 5import { ActorModel } from '../../models/activitypub/actor'