aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/custom-validators/plugins.ts7
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/middlewares/validators/config.ts5
-rw-r--r--server/middlewares/validators/users.ts5
-rw-r--r--server/models/account/user.ts4
5 files changed, 12 insertions, 11 deletions
diff --git a/server/helpers/custom-validators/plugins.ts b/server/helpers/custom-validators/plugins.ts
index 064af9ead..e0a6f98a7 100644
--- a/server/helpers/custom-validators/plugins.ts
+++ b/server/helpers/custom-validators/plugins.ts
@@ -4,7 +4,6 @@ import { PluginType } from '../../../shared/models/plugins/plugin.type'
4import { CONSTRAINTS_FIELDS } from '../../initializers/constants' 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
5import { PluginPackageJson } from '../../../shared/models/plugins/plugin-package-json.model' 5import { PluginPackageJson } from '../../../shared/models/plugins/plugin-package-json.model'
6import { isUrlValid } from './activitypub/misc' 6import { isUrlValid } from './activitypub/misc'
7import { isThemeRegistered } from '../../lib/plugins/theme-utils'
8 7
9const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS 8const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
10 9
@@ -66,8 +65,8 @@ function isCSSPathsValid (css: any[]) {
66 return isArray(css) && css.every(c => isSafePath(c)) 65 return isArray(css) && css.every(c => isSafePath(c))
67} 66}
68 67
69function isThemeValid (name: string) { 68function isThemeNameValid (name: string) {
70 return isPluginNameValid(name) && isThemeRegistered(name) 69 return isPluginNameValid(name)
71} 70}
72 71
73function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) { 72function isPackageJSONValid (packageJSON: PluginPackageJson, pluginType: PluginType) {
@@ -91,7 +90,7 @@ function isLibraryCodeValid (library: any) {
91export { 90export {
92 isPluginTypeValid, 91 isPluginTypeValid,
93 isPackageJSONValid, 92 isPackageJSONValid,
94 isThemeValid, 93 isThemeNameValid,
95 isPluginHomepage, 94 isPluginHomepage,
96 isPluginVersionValid, 95 isPluginVersionValid,
97 isPluginNameValid, 96 isPluginNameValid,
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 4163fe49d..2d487a263 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -171,7 +171,7 @@ const SCHEDULER_INTERVALS_MS = {
171 171
172// --------------------------------------------------------------------------- 172// ---------------------------------------------------------------------------
173 173
174let CONSTRAINTS_FIELDS = { 174const CONSTRAINTS_FIELDS = {
175 USERS: { 175 USERS: {
176 NAME: { min: 1, max: 120 }, // Length 176 NAME: { min: 1, max: 120 }, // Length
177 DESCRIPTION: { min: 3, max: 1000 }, // Length 177 DESCRIPTION: { min: 3, max: 1000 }, // Length
diff --git a/server/middlewares/validators/config.ts b/server/middlewares/validators/config.ts
index 31b131914..9c43da165 100644
--- a/server/middlewares/validators/config.ts
+++ b/server/middlewares/validators/config.ts
@@ -5,7 +5,8 @@ import { logger } from '../../helpers/logger'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { Emailer } from '../../lib/emailer' 6import { Emailer } from '../../lib/emailer'
7import { areValidationErrors } from './utils' 7import { areValidationErrors } from './utils'
8import { isThemeValid } from '../../helpers/custom-validators/plugins' 8import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
9import { isThemeRegistered } from '../../lib/plugins/theme-utils'
9 10
10const customConfigUpdateValidator = [ 11const customConfigUpdateValidator = [
11 body('instance.name').exists().withMessage('Should have a valid instance name'), 12 body('instance.name').exists().withMessage('Should have a valid instance name'),
@@ -48,7 +49,7 @@ const customConfigUpdateValidator = [
48 body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'), 49 body('followers.instance.enabled').isBoolean().withMessage('Should have a valid followers of instance boolean'),
49 body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'), 50 body('followers.instance.manualApproval').isBoolean().withMessage('Should have a valid manual approval boolean'),
50 51
51 body('theme.default').custom(isThemeValid).withMessage('Should have a valid theme'), 52 body('theme.default').custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'),
52 53
53 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 54 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
54 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body }) 55 logger.debug('Checking customConfigUpdateValidator parameters', { parameters: req.body })
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index df7f77b84..a507afc5b 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -28,7 +28,8 @@ import { ActorModel } from '../../models/activitypub/actor'
28import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor' 28import { isActorPreferredUsernameValid } from '../../helpers/custom-validators/activitypub/actor'
29import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' 29import { isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels'
30import { UserRegister } from '../../../shared/models/users/user-register.model' 30import { UserRegister } from '../../../shared/models/users/user-register.model'
31import { isThemeValid } from '../../helpers/custom-validators/plugins' 31import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
32import { isThemeRegistered } from '../../lib/plugins/theme-utils'
32 33
33const usersAddValidator = [ 34const usersAddValidator = [
34 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'), 35 body('username').custom(isUserUsernameValid).withMessage('Should have a valid username (lowercase alphanumeric characters)'),
@@ -207,7 +208,7 @@ const usersUpdateMeValidator = [
207 .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'), 208 .custom(isUserVideosHistoryEnabledValid).withMessage('Should have a valid videos history enabled attribute'),
208 body('theme') 209 body('theme')
209 .optional() 210 .optional()
210 .custom(isThemeValid).withMessage('Should have a valid theme'), 211 .custom(v => isThemeNameValid(v) && isThemeRegistered(v)).withMessage('Should have a valid theme'),
211 212
212 async (req: express.Request, res: express.Response, next: express.NextFunction) => { 213 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
213 logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') }) 214 logger.debug('Checking usersUpdateMe parameters', { parameters: omit(req.body, 'password') })
diff --git a/server/models/account/user.ts b/server/models/account/user.ts
index 6f0b0e00f..0041bf577 100644
--- a/server/models/account/user.ts
+++ b/server/models/account/user.ts
@@ -52,7 +52,7 @@ import { ActorModel } from '../activitypub/actor'
52import { ActorFollowModel } from '../activitypub/actor-follow' 52import { ActorFollowModel } from '../activitypub/actor-follow'
53import { VideoImportModel } from '../video/video-import' 53import { VideoImportModel } from '../video/video-import'
54import { UserAdminFlag } from '../../../shared/models/users/user-flag.model' 54import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
55import { isThemeValid } from '../../helpers/custom-validators/plugins' 55import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
56import { getThemeOrDefault } from '../../lib/plugins/theme-utils' 56import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
57 57
58enum ScopeNames { 58enum ScopeNames {
@@ -191,7 +191,7 @@ export class UserModel extends Model<UserModel> {
191 191
192 @AllowNull(false) 192 @AllowNull(false)
193 @Default(DEFAULT_THEME_NAME) 193 @Default(DEFAULT_THEME_NAME)
194 @Is('UserTheme', value => throwIfNotValid(value, isThemeValid, 'theme')) 194 @Is('UserTheme', value => throwIfNotValid(value, isThemeNameValid, 'theme'))
195 @Column 195 @Column
196 theme: string 196 theme: string
197 197