ActivityPub-federated video streaming platform using P2P directly in your web browser
Prevent shell injection
Chocobozzz383168c8ef05
diff --git a/packages/tests/src/api/server/plugins.ts b/packages/tests/src/api/server/plugins.tsindex fb37d8e3a8..4c8fd91305 100644--- a/packages/tests/src/api/server/plugins.ts+++ b/packages/tests/src/api/server/plugins.ts@@ -329,6 +329,15 @@ describe('Test plugins', function () {expect(user.theme).to.equal('instance-default')})+ it('Should not be able to inject shell command in plugin path', async function () {+ await command.install({+ path: PluginsCommand.getPluginTestPath() + '; touch /tmp/toto.txt',+ expectedStatus: HttpStatusCode.BAD_REQUEST_400+ })++ expect(await pathExists('/tmp/toto.txt')).to.be.false+ })+it('Should not install a broken plugin', async function () {this.timeout(60000)diff --git a/server/core/lib/plugins/package-manager.ts b/server/core/lib/plugins/package-manager.tsindex 1313d81b08..9c4b3398b9 100644--- a/server/core/lib/plugins/package-manager.ts+++ b/server/core/lib/plugins/package-manager.ts@@ -1,8 +1,8 @@import { isStableOrUnstableVersionValid } from '@server/helpers/custom-validators/misc.js'+import { execa } from 'execa'import { outputJSON, pathExists, remove } from 'fs-extra/esm'import { readFile, writeFile } from 'fs/promises'import { join } from 'path'-import { execShell } from '../../helpers/core-utils.js'import { isNpmPluginNameValid } from '../../helpers/custom-validators/plugins.js'import { logger } from '../../helpers/logger.js'import { CONFIG } from '../../initializers/config.js'@@ -18,34 +18,34 @@ export async function installNpmPlugin (npmName: string, versionArg?: string) {let toInstall = npmNameif (version) toInstall += `@${version}`- const { stdout } = await execPNPM('add ' + toInstall)+ const { stdout } = await execPNPM([ 'add', toInstall ])logger.debug('Added a pnpm package.', { stdout })}export async function installNpmPluginFromDisk (path: string) {- await execPNPM('add file:' + path)+ await execPNPM([ 'add', 'file:' + path ])}export async function removeNpmPlugin (name: string) {checkNpmPluginNameOrThrow(name)- await execPNPM('remove ' + name)+ await execPNPM([ 'remove', name ])}export async function rebuildNativePlugins () {- await execPNPM('rebuild')+ await execPNPM([ 'rebuild' ])}// ----------------------------------------------------------------------------async function execPNPM (command: string) {+async function execPNPM (commands: string[]) {try {const pluginDirectory = CONFIG.STORAGE.PLUGINS_DIR- return execShell(`pnpm ${command}`, { cwd: pluginDirectory })+ return execa('pnpm', commands, { cwd: pluginDirectory })} catch (result) {- logger.error('Cannot exec pnpm.', { command, err: result.err, stderr: result.stderr })+ logger.error('Cannot exec pnpm.', { commands, err: result.err, stderr: result.stderr })throw result.err as Error}@@ -102,7 +102,7 @@ export async function initPNPM () {logger.info('Migrate from yarn.lock in plugin directory')try {- await execPNPM('import')+ await execPNPM([ 'import' ])await remove(join(pluginDirectory, 'yarn.lock'))} catch (err) {logger.error(