Is It Safe to Keep HTTP Enabled While Using HSTS for a Custom curl Response?

0
2
Asked By MellowCedar42 On

I want to show a custom response when I run `curl mydomain.tld`, so I have HSTS enabled but have not enabled the server's Force HTTPS option. This lets plain HTTP requests return my custom message, while browsers that know about HSTS use HTTPS automatically. I could also run `curl https://mydomain.tld`, but I prefer the shorter command. The site is a small static personal portfolio with no login or sensitive data, plus a read-only API request to display contribution information. Is leaving HTTP enabled this way a security risk?

3 Answers

Answered By CopperMoth58 On

For a personal static site with no credentials, cookies, private data, or meaningful user actions, the practical risk is fairly small. However, anyone whose first request is made over HTTP, or whose client does not support or remember HSTS, can still receive the page unencrypted. On an untrusted network, that traffic could be observed or modified. Production sites should generally redirect HTTP to HTTPS instead of serving content over both protocols.

Answered By SilverPanda26 On

You can keep the short command without leaving HTTP enabled by setting curl’s default protocol to HTTPS. Another option is to return the custom message based on the User-Agent or use a separate hostname or virtual host. HSTS is defense in depth, not a replacement for an HTTP-to-HTTPS redirect, and it is only effective after a client has learned the policy unless the domain is included in an HSTS preload list.

Answered By BrightLynx7 On

HSTS does not redirect HTTP requests on the server. It tells browsers that have already received the policy over HTTPS to upgrade future requests before connecting. It also does not help clients such as curl unless curl is explicitly given an HTTPS URL or configured to default to HTTPS. The safer server setup is to redirect every HTTP request to HTTPS and configure curl locally instead. For example, a `~/.curlrc` entry such as `proto-default = "https"` lets you keep using `curl mydomain.tld` without exposing an HTTP endpoint.

QuietHarbor19 -

Some operating systems may already configure similar behavior, but it is still worth checking what your curl installation actually does rather than relying on that.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.