brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl --proto =https refuses anything but HTTPS

Curl
~/tips/tip-curl-proto-https-only

curl --proto =https --proto-redir =https -L -o install.sh https://example.com/install.sh

Limits curl and its redirects to HTTPS so a link can never downgrade to plain HTTP.

I am happy to have a script follow redirects, but I do not want it to end up on plain HTTP or some other protocol halfway through. curl has an allow list for that.

--proto limits which protocols curl may use for a transfer. The list is comma separated and read from left to right, and each entry can have a modifier: + adds a protocol, - removes one and = permits only that protocol. For a download that must stay on HTTPS:

curl --proto =https --proto-redir =https -L -o install.sh https://example.com/install.sh

--proto covers the first request and --proto-redir covers the redirects that -L follows. If the server answers with a redirect to http://, curl now refuses it instead of quietly downgrading. The manual notes that protocols denied by --proto are not re-enabled by --proto-redir.

Out of the box, curl only allows HTTP, HTTPS, FTP and FTPS on redirects. Setting --proto-redir to all turns every protocol on for redirects, and the manual itself says that is not good for security, so I would not do it.

Some more examples straight from the manual: --proto -ftps keeps the defaults but disables FTPS, and --proto -all,https,+http enables only HTTP and HTTPS.

The caveat is that this is a hard stop. A site that still redirects from HTTPS to HTTP, or a mirror that lives on FTP, will simply fail with an error. That is what I want in an install script, but it can surprise you with an old download link. Also note that an unknown or disabled protocol name only produces a warning, so a typo in the list does not stop curl by itself. I would run the command once by hand and check that it behaves.

Further reading: curl man page: –proto and –proto-redir

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link