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

Fre let's you execute arbitrary shell commands #219

Open
uwagura opened this issue Oct 25, 2024 · 7 comments
Open

Fre let's you execute arbitrary shell commands #219

uwagura opened this issue Oct 25, 2024 · 7 comments
Labels
bug Something isn't working priority: HIGH

Comments

@uwagura
Copy link

uwagura commented Oct 25, 2024

Describe the bug
Since fre uses shell=True when running subprocesses, you can pass in arbitrary shell commands to fre, which is a security risk

fre-cli/fre/pp/status.py

Lines 14 to 15 in d1457e2

cmd = f"cylc workflow-state {name}"
subprocess.run(cmd, shell=True, check=True, timeout=30)

To Reproduce
fre/canopy will execute the shell commands within the following command

fre pp status -e ";cat ~/.ssh/id_rsa;" -p ";touch unwanted_file.txt;" -t ";echo $USER;"

Expected behavior
fre should ignore shell commands passed as arguments into the function

Additional context
In practice, this probably isn't a big issue for fre since fre users won't have the ability to manipulate other peoples data and probably won't pass anything that can be interpreted as a shell command to fre. Still, it may be worth removing the shell=True argument from fre just for best practice reasons. It looks like the recommended way to do this is to change the above command to:

subprocess.run(['cylc','workflow-state',name], check=True, timeout=50)

And likewise, to do the same everywhere where subprocess.run is called with the shell=True argument

@ilaflott
Copy link
Member

wow this is the most validating thing i have ever seen

@ceblanton
Copy link
Collaborator

ceblanton commented Oct 25, 2024

Thank you so much @uwagura for raising this issue. I 100% agree with you, and feel that that ALL external shell calls be immediately outlawed and existing usage should be removed.

All of the cylc and isodatetime and other similar usages could be rephrased as native python using the cylc, isodatetime, and other python interfaces. The existing usage is really first-draft, and not proper I agree. Thank you again for bringing this up.

Can we outlaw external shell calls through pylint?

@cwhitlock-NOAA
Copy link
Collaborator

cwhitlock-NOAA commented Oct 25, 2024 via email

@ceblanton
Copy link
Collaborator

Let's take the existing shell usages case-by-case, and give exceptions for ones that don't have python interfaces. I agree with you there could be some essential needs for shell calls in those cases.

@ceblanton
Copy link
Collaborator

Bronx fre-commands has a super-rich use of Linux shell utilities, so there's nothing wrong with shell calls, but I would say it's more proper to use native python interfaces if possible, and also the security argument.

What about potential use of fre-cli on Windows (shudder) as motivation for going shell-free, even if we don't have to. Shell calls can't work on Windows, I would guess.

@ilaflott
Copy link
Member

ilaflott commented Oct 25, 2024

@ilaflott
Copy link
Member

about 13 instances of subprocess.run calls- not too embedded in the code base to sanitize at all.

only two POpens thankfully

@ilaflott ilaflott added bug Something isn't working priority: HIGH labels Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: HIGH
Projects
None yet
Development

No branches or pull requests

4 participants