|
@@ -72,8 +72,16 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
|
|
|
|
|
// if not exists repository in file system, download latest plugin repository
|
|
// if not exists repository in file system, download latest plugin repository
|
|
|
for await (const growiPlugin of growiPlugins) {
|
|
for await (const growiPlugin of growiPlugins) {
|
|
|
- const pluginPath = path.join(PLUGIN_STORING_PATH, growiPlugin.installedPath);
|
|
|
|
|
- const organizationName = path.join(PLUGIN_STORING_PATH, growiPlugin.organizationName);
|
|
|
|
|
|
|
+ let pluginPath :fs.PathLike|undefined;
|
|
|
|
|
+ let organizationName :fs.PathLike|undefined;
|
|
|
|
|
+ try {
|
|
|
|
|
+ pluginPath = this.joinAndValidatePath(PLUGIN_STORING_PATH, growiPlugin.installedPath);
|
|
|
|
|
+ organizationName = this.joinAndValidatePath(PLUGIN_STORING_PATH, growiPlugin.organizationName);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.error(err);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
if (fs.existsSync(pluginPath)) {
|
|
if (fs.existsSync(pluginPath)) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -301,22 +309,34 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const growiPluginsPath = path.join(PLUGIN_STORING_PATH, growiPlugins.installedPath);
|
|
|
|
|
- await deleteFolder(growiPluginsPath);
|
|
|
|
|
|
|
+ await GrowiPlugin.deleteOne({ _id: pluginId });
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
logger.error(err);
|
|
|
- throw new Error('Failed to delete plugin repository.');
|
|
|
|
|
|
|
+ throw new Error('Failed to delete plugin from GrowiPlugin documents.');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ let growiPluginsPath: fs.PathLike | undefined;
|
|
|
try {
|
|
try {
|
|
|
- await GrowiPlugin.deleteOne({ _id: pluginId });
|
|
|
|
|
|
|
+ growiPluginsPath = this.joinAndValidatePath(PLUGIN_STORING_PATH, growiPlugins.installedPath);
|
|
|
}
|
|
}
|
|
|
catch (err) {
|
|
catch (err) {
|
|
|
logger.error(err);
|
|
logger.error(err);
|
|
|
- throw new Error('Failed to delete plugin from GrowiPlugin documents.');
|
|
|
|
|
|
|
+ throw new Error('The installedPath for the plugin is invalid, and the plugin has already been removed.');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (growiPluginsPath && fs.existsSync(growiPluginsPath)) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ await deleteFolder(growiPluginsPath);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ logger.error(err);
|
|
|
|
|
+ throw new Error('Failed to delete plugin repository.');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else {
|
|
|
|
|
+ logger.warn(`Plugin path does not exist : ${growiPluginsPath}`);
|
|
|
|
|
+ }
|
|
|
return growiPlugins.meta.name;
|
|
return growiPlugins.meta.name;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -402,6 +422,17 @@ export class GrowiPluginService implements IGrowiPluginService {
|
|
|
return entries;
|
|
return entries;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private joinAndValidatePath(baseDir: string, ...paths: string[]):fs.PathLike {
|
|
|
|
|
+ const joinedPath = path.join(baseDir, ...paths);
|
|
|
|
|
+ if (!joinedPath.startsWith(baseDir)) {
|
|
|
|
|
+ throw new Error(
|
|
|
|
|
+ 'Invalid plugin path detected! Access outside of the allowed directory is not permitted.'
|
|
|
|
|
+ + `\nAttempted Path: ${joinedPath}`,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ return joinedPath;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|