Skip to content
Open
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
15 changes: 15 additions & 0 deletions src/spark_cli/security/approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ def approval_required_for_command(argv: list[str], context: CommandContext | Non
confirmation_phrase="approve remote code execution",
)

if (
first == "npx"
or (first == "npm" and second == "exec")
or (first in {"pnpm", "yarn"} and second == "dlx")
):
return _decision(
parts,
ctx,
"remote_code_execution",
"critical",
"Command can download and execute package code through a package runner.",
target_display=" ".join(parts[:3]),
confirmation_phrase="approve remote code execution",
)

if first == "find" and any(part in {"-exec", "-execdir"} for part in lowered):
return _decision(
parts,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,20 @@ def test_approval_classifier_flags_remote_script_execution(self) -> None:
self.assertEqual(decision.action_class, "remote_code_execution")
self.assertEqual(decision.risk, "critical")

def test_approval_classifier_flags_package_runner_execution(self) -> None:
for command in (
["npx", "--yes", "cowsay@latest", "hello"],
["npm", "exec", "--yes", "cowsay@latest", "--", "hello"],
["pnpm", "dlx", "cowsay@latest", "hello"],
["yarn", "dlx", "cowsay@latest", "hello"],
):
with self.subTest(command=command):
decision = approval_required_for_command(command, CommandContext(hosted=True, non_interactive=True))
self.assertTrue(decision.requires_approval)
self.assertEqual(decision.action_class, "remote_code_execution")
self.assertEqual(decision.risk, "critical")
self.assertEqual(decision.approval_mode, "blocked")

def test_approval_classifier_does_not_treat_curl_fail_or_telnet_option_as_upload(self) -> None:
for command in (
["curl", "-f", "https://example.test/health"],
Expand Down
Loading