curl | bad

curl | bad

NOTE: the image for this blog post is because we are talking about something in ๐Ÿ˜๏ธ

I know that doing curl and directly pipe'ing into bash is considered a bad practice for security, and people discourage it.

When it comes to automation though, sometimes there is no way to get around people doing it. So here are a few practical things to do if you are going to do that.

  1. Do a curl -fsSLI on the url. This will show you the headers of where you would be going without actually navigating you to the contents of the file yet. You can checkout more about the above command here:

  2. do a curl -fsSL 'https://url' | $EDITOR - , so you can inspect the contents of what the script is doing to your device. This is EXTREMELY important, because once you curl to bash there is no going back...

  3. If you want to, to make sure it doesnโ€™t do anything bad, do it inside a VM (Virtual Machine) or container. If you use vagrant or docker spinning up a VM is only a few more seconds to a minute that could prevent someone messing up your machine.

    • for docker you can do this command, so you get the official container that has curl
    docker container run --rm --cap-drop all -it curlimages/curl /bin/sh
  4. This one is a bash trick, so I learned from making packer template and observing the bento project ( one of the flags they use is the -x option for sh. While it might not be apparent when thinking about moving from scripting to regular cli, you can specify that flag during run time of a script to do โ€œdebugโ€ mode and bash supports it too

    • I couldnโ€™t find a good place to reference bashโ€™s man page (excpet on my linux machine), but there are two ways to look at it if you are on a linux machine
      • if you are running bash do help set and you should get all the necessary information
      • if you aren't running bash do man bash you should be able to see

        All of the single-character shell options documented in the description of the set builtin command

    and is an explanation of that option.

So, an example for running one of my scripts from a blog post (https://blog.elreydetoda.sitehttps://blog.elreydetoda.site is as follows:

curl -fsSL '' | bash -xs '24' '' ''
  1. Lastly make sure that the scripts you are pipe'ing to bash are by a trusted authority or some one you can trust to take proper security precautions. A great example is installing docker: