feat: upon plugin installation via ACP, check against nbbpm first

v1.18.x
Julian Lam 5 years ago
parent 8b855720f8
commit 5ddf70221c

@ -200,5 +200,7 @@
"cannot-block-guest": "Guest are not able to block other users",
"already-blocked": "This user is already blocked",
"already-unblocked": "This user is already unblocked",
"no-connection": "There seems to be a problem with your internet connection"
"no-connection": "There seems to be a problem with your internet connection",
"plugin-not-whitelisted": "Unable to install plugin – only plugins whitelisted by the NodeBB Package Manager can be installed via the ACP"
}

@ -7,6 +7,7 @@ const nconf = require('nconf');
const os = require('os');
const cproc = require('child_process');
const util = require('util');
const request = require('request-promise-native');
const db = require('../database');
const meta = require('../meta');
@ -66,6 +67,20 @@ module.exports = function (Plugins) {
return { id: id, active: !isActive };
};
Plugins.checkWhitelist = async function (id, version) {
const body = await request({
method: 'GET',
url: `https://packages.nodebb.org/api/v1/plugins/${encodeURIComponent(id)}`,
json: true,
});
if (body && body.code === 'ok' && (version === 'latest' || body.payload.valid.includes(version))) {
return;
}
throw new Error('[[error:plugin-not-whitelisted]]');
};
Plugins.toggleInstall = async function (id, version) {
pubsub.publish('plugins:toggleInstall', { hostname: os.hostname(), id: id, version: version });
return await toggleInstall(id, version);

@ -19,6 +19,7 @@ Plugins.toggleActive = async function (socket, plugin_id) {
Plugins.toggleInstall = async function (socket, data) {
require('../../posts/cache').reset();
await plugins.checkWhitelist(data.id, data.version);
const pluginData = await plugins.toggleInstall(data.id, data.version);
await events.log({
type: 'plugin-' + (pluginData.installed ? 'install' : 'uninstall'),

Loading…
Cancel
Save