Skip to content
Merged
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
10 changes: 10 additions & 0 deletions PR_DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 🔒 Security Fix: Replace unsafe `preexec_fn` with `start_new_session`

🎯 **What:**
Replaced `preexec_fn=os.setsid` with `start_new_session=True` in `subprocess.Popen` within `commando/core/audit.py`.

⚠️ **Risk:**
Using `preexec_fn` in Python can lead to severe security and stability issues in multi-threaded applications. Specifically, if a thread holds a lock or forks concurrently, running an arbitrary callable via `preexec_fn` just before `exec()` can cause the child process to deadlock, potentially leading to denial of service or unexpected program crashes. This is a well-documented risk in the Python standard library.

🛡️ **Solution:**
Python 3.2+ introduced the `start_new_session` parameter to `subprocess.Popen` specifically to handle the common use case of running `os.setsid` safely. By switching to `start_new_session=True`, the child process continues to start in a new process group without risking deadlocks from concurrent threading operations, ensuring safe and reliable dynamic auditing (e.g., via `strace`).
Comment on lines +1 to +10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It appears that PR_DESCRIPTION.md was accidentally committed to the repository. This file contains the pull request description, which should only be submitted as the PR body on GitHub/GitLab rather than being tracked in version control. Please delete this file from the repository.

12 changes: 8 additions & 4 deletions commando/core/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ def search_command(
execute_strace = False
else:
try:
ans = input(
f"{YELLOW}Warning: '{base_command}' is a custom import. Append '--help' for kinetic audit? (y/N): {RESET}"
).strip().lower()
ans = (
input(
f"{YELLOW}Warning: '{base_command}' is a custom import. Append '--help' for kinetic audit? (y/N): {RESET}"
)
.strip()
.lower()
)
except (EOFError, KeyboardInterrupt):
ans = "n"

Expand All @@ -98,7 +102,7 @@ def search_command(
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
preexec_fn=os.setsid,
start_new_session=True,
)

try:
Expand Down
Loading