diff --git a/server/core/helpers/custom-validators/plugins.ts b/server/core/helpers/custom-validators/plugins.ts index 99ee476b7..521458c83 100644 --- a/server/core/helpers/custom-validators/plugins.ts +++ b/server/core/helpers/custom-validators/plugins.ts @@ -6,6 +6,10 @@ import { exists, isArray, isSafePath } from './misc.js' const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS +const NPM_VALIDATION_RE = new RegExp( + /^(@[^\._][a-z-_\.~0-9]+\/)?([a-z-0-9]+)$/, +); + function isPluginTypeValid (value: any) { return exists(value) && (value === PluginType.PLUGIN || value === PluginType.THEME) @@ -14,14 +18,16 @@ function isPluginTypeValid (value: any) { function isPluginNameValid (value: string) { return exists(value) && validator.default.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) && - validator.default.matches(value, /^[a-z-0-9]+$/) + validator.default.matches(value, NPM_VALIDATION_RE) } function isNpmPluginNameValid (value: string) { + const match = value.match(NPM_VALIDATION_RE); return exists(value) && validator.default.isLength(value, PLUGINS_CONSTRAINTS_FIELDS.NAME) && - validator.default.matches(value, /^[a-z\-._0-9]+$/) && - (value.startsWith('peertube-plugin-') || value.startsWith('peertube-theme-')) + validator.default.matches(value, NPM_VALIDATION_RE) && + (match[2].startsWith("peertube-plugin-") || + match[2].startsWith("peertube-theme-")) } function isPluginDescriptionValid (value: string) {