Skip to content

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

Open
@gunnsth

Description

@gunnsth

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions