mirror of
https://github.com/rohitg00/skillkit.git
synced 2026-11-19 02:13:58 +00:00
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:
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user