Skip to content

Commit

Permalink
feat: whitelist some commands
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Oct 9, 2024
1 parent 578adcc commit be234fb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gptme/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,20 @@ def execute_shell(
assert not args

cmd = code.strip()
whitelisted = False
if cmd.startswith("$ "):
cmd = cmd[len("$ ") :]

single_cmd = code.count("\n")
is_safe_cmd = False
if single_cmd < 1:
is_safe_cmd = any(code.startswith(safe_cmd) for safe_cmd in ['ls', 'stat', 'cd', 'cat'])

if single_cmd < 1 and is_safe_cmd:
whitelisted = True

confirm = True
if ask:
if not whitelisted and ask:
print_preview(f"$ {cmd}", "bash")
confirm = ask_execute()
print()
Expand Down

0 comments on commit be234fb

Please sign in to comment.