Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ability to disallow certain shell commands #3707

Closed
wants to merge 6 commits into from

Conversation

bassie661
Copy link

A simple "if any" to be able to set disallowed shell commands in the .env

Background

Many times I encountered an agent getting stuck when starting a GUI application like vi or nano via the execute_shell command. Resulting in auto-GPT waiting endlessly until I either killed the command through another terminal session or I had to completely abandon the session with CTRL+C.

The GUI applications nano and vi or gedit are unnecessary as auto-GPT has the write_to_file and append_to_file commands to take care of that.

Changes

To be able to set the disallowed commands, I added the parameter "DISALLOWED_COMMANDS" to the .env.template.

Documentation

In the .env file you can set the DISALLOWED_COMMANDS, comma separated like DISALLOWED_COMMANDS=nano,vi,gedit

The variable DISALLOWED_COMMANDS can contain commands with spaces. The code that checks for disallowed commands isn't designed to handle complex commands with arguments, it's just looking for specific command names in the input string. If we need to handle complex commands, we may need a more sophisticated approach.

Test Plan

Tested with various goals which might triggered commands that we want to disallow, like nano, vi, gedit.

PR Quality Checklist

  • My pull request is atomic and focuses on a single change.
  • I have thoroughly tested my changes with multiple different prompts.
  • I have considered potential risks and mitigations for my changes.
  • I have documented my changes clearly and comprehensively.
  • I have not snuck in any "extra" small tweaks changes

A simple "if any" to be able to set disallowed shell commands in the .env
added comment
@vercel
Copy link

vercel bot commented May 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) May 22, 2023 8:47am

@github-actions github-actions bot added the size/m label May 2, 2023
Copy link
Member

@ntindle ntindle left a comment

Choose a reason for hiding this comment

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

Wait for #3669 #3663 #3653

autogpt/commands/execute_code.py Outdated Show resolved Hide resolved
A lot of times agents come up with arguments against list_files() which are not accepted, this makes the agent end up in a loop, while a lot of times the args are just a replacement of the original "filename" argument, and i've also seen extension as an argument, with literally an ".ext" as search argument. Changed the function to accept all, it might be better to take care of this on the agent side, but in the meantime I couldn't take it anymore :)
added load_disallowed_commands() function to load from OS.env and pass them to the execute_shell function
Copy link
Author

@bassie661 bassie661 left a comment

Choose a reason for hiding this comment

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

submitted

@p-i-
Copy link
Contributor

p-i- commented May 5, 2023

This is a mass message from the AutoGPT core team.
Our apologies for the ongoing delay in processing PRs.
This is because we are re-architecting the AutoGPT core!

For more details (and for infor on joining our Discord), please refer to:
https://github.com/Significant-Gravitas/Auto-GPT/wiki/Architecting

@Wladastic
Copy link
Contributor

Wladastic commented May 5, 2023

I did a similar check, but also did a whitelist as well.
You could add an optional whitelist and those defaults I used, I just added a few bad bad ones, decide if you want those haha ( I didn't create a pr):

WHITELIST_COMMANDS = ["ls", "git", "cat", "grep", "find", "echo", "ps", "top", "df", "du", "uname", "whoami", "date", "uptime", "free", "curl", "wget", "tar", "zip", "unzip", "gzip", "gunzip", "bzip2", "bunzip2", "ssh", "scp", "rsync", "ping", "traceroute", "dig", "host", "nslookup", "ifconfig", "ip", "route", "netstat", "ss", "lsof", "kill", "killall", "pkill", "pgrep", "ps", "pstree"]
DISALLOWED_KEYWORDS = ["cd", "nano", "vim", "vi", "emacs", "rm", "sudo", "|", ">", "<"]

def validate_command(command: str) -> bool:
    tokens = command.split()
    if not tokens:
        return False

    if WHITELIST_COMMANDS and tokens[0] not in WHITELIST_COMMANDS:
        return False

    for keyword in DISALLOWED_KEYWORDS:
        if keyword in tokens:
            return False

    return True

@anonhostpi
Copy link

anonhostpi commented May 5, 2023

I think this would make more sense as a docker feature. There are user-security level methods to prevent this. Hard-coding in limitations doesn't seem like a secure practice. All it takes is for an agent/human to lookup workarounds around the prohibited commands in the repo's source code or the config files.

@Wladastic
Copy link
Contributor

I think this would make more sense as a docker feature. There are user-security level methods to prevent this. Hard-coding in limitations doesn't seem like a secure practice. All it takes is for an agent/human to lookup workarounds around the prohibited commands in the repo's source code or the config files.

Those are supposed to be optional defaults in the .env, not hardcoded. Just like categories of commands that can be disallowed.

@anonhostpi
Copy link

Well the parser/filter for them is hardcoded. There are other security tools for this. I don't recommend implementing this feature this way.

I do think its a good feature, just a bad implementation.

All the agent has to do is read the .env file and it can come up with workarounds.

@Boostrix
Copy link
Contributor

Other than that, there's more than just one blacklist/whitelist feature now for the shell execution feature.

@gravelBridge gravelBridge added enhancement New feature or request potential plugin This may fit better into our plugin system. function: run shell commands labels May 17, 2023
@github-actions github-actions bot added the conflicts Automatically applied to PRs with merge conflicts label May 19, 2023
@github-actions
Copy link
Contributor

This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.

@bassie661
Copy link
Author

This one can be closed as it was taken care if with #3950

@bassie661 bassie661 closed this May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conflicts Automatically applied to PRs with merge conflicts enhancement New feature or request function: run shell commands potential plugin This may fit better into our plugin system. Security 🛡️ size/l
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants