Skip to content

Commit

Permalink
fix: prevent yarn directory traversal on plugin installation (#6829)
Browse files Browse the repository at this point in the history
* fix: prevent yarn directory traversal on plugin installation
fixes #4041

* fix: fix code formatting in `install-plugin.ts`
  • Loading branch information
techchrism authored Feb 7, 2025
1 parent d8803b8 commit cf42d46
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/insomnia/src/main/install-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cp, mkdir, readdir, stat } from 'node:fs/promises';
import { cp, mkdir, readdir, stat, writeFile } from 'node:fs/promises';

import childProcess from 'child_process';
import * as electron from 'electron';
Expand Down Expand Up @@ -162,6 +162,8 @@ async function _installPluginToTmpDir(lookupName: string) {
return new Promise<{ tmpDir: string }>(async (resolve, reject) => {
const tmpDir = path.join(electron.app.getPath('temp'), `${lookupName}-${Date.now()}`);
await mkdir(tmpDir, { recursive: true });
// Write a dummy package.json so that yarn doesn't traverse up the directory tree
await writeFile(path.join(tmpDir, 'package.json'), JSON.stringify({ license: 'ISC', workspaces: [] }), 'utf-8');

console.log(`[plugins] Installing plugin to ${tmpDir}`);
childProcess.execFile(
Expand All @@ -178,6 +180,7 @@ async function _installPluginToTmpDir(lookupName: string) {
'--no-lockfile',
'--production',
'--no-progress',
'--ignore-workspace-root-check',
],
{
timeout: 5 * 60 * 1000,
Expand Down

0 comments on commit cf42d46

Please sign in to comment.