Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: plugin/theme names with scope are not allowed #6882

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions server/core/helpers/custom-validators/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down