Skip to content

Commit 73306da

Browse files
[Security] Add command safety check to execCommand
This change adds a call to `checkCommandSafety` in the `execCommand` function in `packages/cli-kit/src/public/node/system.ts`. This ensures that any command executed via `execCommand` is checked for unsecure binaries in the current working directory, preventing binary planting/PATH hijacking attacks. A test case has been added to `packages/cli-kit/src/public/node/system.test.ts` to verify this behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c3e54be commit 73306da

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/cli-kit/src/public/node/system.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,17 @@ describe('execCommand', () => {
266266
// Then
267267
expect(execaCommand).toHaveBeenCalledWith('cat', expect.objectContaining({stdin: 'inherit'}))
268268
})
269+
270+
test('raises an error if the command to run is found in the current directory', async () => {
271+
// Given
272+
vi.mocked(which.sync).mockReturnValueOnce('/currentDirectory/command')
273+
274+
// When
275+
const got = system.execCommand('command', {cwd: '/currentDirectory'})
276+
277+
// Then
278+
await expect(got).rejects.toThrowError('Skipped run of unsecure binary command found in the current directory.')
279+
})
269280
})
270281

271282
describe('isStdinPiped', () => {

packages/cli-kit/src/public/node/system.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ export async function execCommand(command: string, options?: ExecOptions): Promi
206206
env.FORCE_COLOR = '1'
207207
}
208208
const executionCwd = options?.cwd ?? cwd()
209+
const [cmd] = parseCommand(command)
210+
if (cmd) {
211+
checkCommandSafety(cmd, {cwd: executionCwd})
212+
}
209213
try {
210214
await execaCommand(command, {
211215
env,

0 commit comments

Comments
 (0)