Skip to content

How to whitelist commands and handle unsafe input in sys.exec? #923

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

Open
gunnsth opened this issue Dec 26, 2024 · 0 comments
Open

How to whitelist commands and handle unsafe input in sys.exec? #923

gunnsth opened this issue Dec 26, 2024 · 0 comments

Comments

@gunnsth
Copy link

gunnsth commented Dec 26, 2024

Question

I’m pretty new to gptscript and have a question about safely executing commands with sys.exec (or similar features). Is there a built-in way to:

  1. Whitelist Commands:

    • Allow only specific commands to be executed, either by binary name (e.g., ls) or absolute path (e.g., /bin/ls)?
    • Raise an error or ignore commands that are not explicitly allowed?
  2. Filter Unsafe Input:

    • Prevent execution of inputs containing special shell symbols like \``, |, $, ;, or &&`, which could spawn additional processes?
    • For example, how would the library handle inputs like ls -al $(pwd) or echo $(rm -rf /) or ls -al `pwd` etc.?
    • Can users provide a custom validation or sanitization function for input arguments to enforce stricter security?
  3. Safety Guarantees:

    • Are there existing mechanisms in the library to ensure these concerns are handled safely, or would these need to be implemented by the user?

Context

I want to ensure that commands executed through the library are secure and controlled, particularly in scenarios where user-provided input is involved.

Running commands through firejail or something like that could also make sense to have a completely controlled environment (at least on linux).

Any guidance on how to approach this would be greatly appreciated. Thanks for creating such an awesome tool!

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

No branches or pull requests

1 participant