Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/plugin-cloudflare/src/install-cloudflared.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('install-cloudflare', () => {
const binPath = joinPath(tmpDir, 'cloudflared')
const env = {SHOPIFY_CLI_CLOUDFLARED_PATH: binPath}
mockFetch()
vi.mocked(childProcess.execSync).mockImplementation((_command, options) => {
vi.mocked(childProcess.execFileSync).mockImplementation((_command, _args, options) => {
// Simulate tar extracting the file
const cwd = options?.cwd as string
writeFileSync(joinPath(cwd, 'cloudflared'), 'extracted binary')
Expand All @@ -69,7 +69,7 @@ describe('install-cloudflare', () => {
const binPath = joinPath(tmpDir, 'cloudflared')
const env = {SHOPIFY_CLI_CLOUDFLARED_PATH: binPath}
mockFetch()
vi.mocked(childProcess.execSync).mockImplementation((_command, options) => {
vi.mocked(childProcess.execFileSync).mockImplementation((_command, _args, options) => {
const cwd = options?.cwd as string
writeFileSync(joinPath(cwd, 'cloudflared'), 'extracted binary')
return Buffer.from('')
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-cloudflare/src/install-cloudflared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {fileURLToPath} from 'url'
import util from 'util'
import {pipeline} from 'stream'
// eslint-disable-next-line no-restricted-imports
import {execSync, execFileSync} from 'child_process'
import {execFileSync} from 'child_process'

export const CURRENT_CLOUDFLARE_VERSION = '2024.8.2'
const CLOUDFLARE_REPO = `https://github.com/cloudflare/cloudflared/releases/download/${CURRENT_CLOUDFLARE_VERSION}/`
Expand Down Expand Up @@ -132,7 +132,8 @@ async function installWindows(file: string, binTarget: string) {
async function installMacos(file: string, binTarget: string) {
await downloadFile(file, `${binTarget}.tgz`)
const filename = basename(`${binTarget}.tgz`)
execSync(`tar -xzf ${filename}`, {cwd: dirname(binTarget)})
// Use execFileSync to avoid shell interpretation and mitigate command injection
execFileSync('tar', ['-xzf', filename], {cwd: dirname(binTarget)})
unlinkFileSync(`${binTarget}.tgz`)
await renameFile(`${dirname(binTarget)}/cloudflared`, binTarget)
}
Expand Down
Loading