Skip to content

Fix: Remove unsafe exec(raw_command) and restrict command field to app functions#2247

Open
Yunkaiwjs wants to merge 1 commit into
Miserlou:masterfrom
Yunkaiwjs:fix/remove-unsafe-exec-and-restrict-command
Open

Fix: Remove unsafe exec(raw_command) and restrict command field to app functions#2247
Yunkaiwjs wants to merge 1 commit into
Miserlou:masterfrom
Yunkaiwjs:fix/remove-unsafe-exec-and-restrict-command

Conversation

@Yunkaiwjs

Copy link
Copy Markdown

Summary

This PR fixes two high-severity security vulnerabilities in the Lambda handler:

Vulnerability 1: Remote Code Execution via exec(raw_command) (CVE-94, CVSS 8.6)

The raw_command field from the Lambda event dictionary was passed directly to exec() with zero sanitization, allowing arbitrary Python code execution from any Lambda event source.

Fix: Removed the direct exec() call. The raw_command handler now raises a ValueError to prevent any code execution. This is the safest approach since exec() on externally-controlled input cannot be safely sanitized.

Vulnerability 2: Arbitrary Module Import via command Field (CVE-94, CVSS 7.5)

The command event field allowed importing any Python module and calling any function via importlib.import_module(), enabling attackers to invoke arbitrary system functions.

Fix: Added a module whitelist check that restricts command invocations to functions within the configured APP_MODULE only. This ensures only the application's own functions can be invoked via this mechanism.

Test Update

  • Updated tests_placebo.py to expect a ValueError when raw_command is used, matching the new security behavior.

Files Changed

  • zappa/handler.py: Security fixes for both vulnerabilities
  • tests/tests_placebo.py: Updated test expectations

…p functions

- CVE-94 Code Injection: Removed direct exec() of raw_command from Lambda events.
  Replaced with ValueError to prevent arbitrary Python code execution.
- CVE-94 Arbitrary module import: Restricted the 'command' event field to only
  allow functions from the configured APP_MODULE, preventing arbitrary
  module/function imports from unsanitized event data.
- Updated test for raw_command to expect ValueError.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant