fix: allow scoped npm names in isValidPluginName

Update isValidPluginName to allow scoped npm package names like @scope/name
while still preventing path traversal attacks. Uses the same regex pattern
as loader.ts validatePlugin for consistency.

Valid names: my-plugin, @scope/plugin-name
Invalid names: ../evil, .hidden, name\\path, @../evil/name
This commit is contained in:
Rohit Ghumare
2026-01-23 22:27:37 +00:00
parent dcf12f6826
commit 380188cef1
+11 -7
View File
@@ -123,15 +123,19 @@ export class PluginCommand extends Command {
/**
* Validate plugin name to prevent path traversal attacks
* Allows scoped npm names like @scope/name (mirrors loader.ts validation)
*/
private isValidPluginName(name: string): boolean {
// Reject empty, path separators, or path traversal sequences
return Boolean(name) &&
!name.includes('/') &&
!name.includes('\\') &&
!name.includes('..') &&
name !== '.' &&
!name.startsWith('.');
if (!name) return false;
// Reject backslashes, path traversal sequences, and names starting with '.'
if (name.includes('\\') || name.includes('..') || name === '.' || name.startsWith('.')) {
return false;
}
// Allow scoped npm names (@scope/name) or simple names (no slashes)
// Use the same regex pattern as loader.ts validatePlugin
return /^(?:@[a-z0-9-]+\/)?[a-z0-9-]+$/.test(name);
}
private async installPlugin(pluginManager: ReturnType<typeof createPluginManager>): Promise<number> {