Configuring on Apache HTTPD server, many articles on the web advise to enforce HTTPS protocol by redirecting (permanently) all HTTP request to HTTPS.
Below is what I understand is happening when a user tries to reach a server supporting both HTTP and HTTPS :
- Client's user agent (web browser for example, but not only) sends a request to http://my.domain.com.
- Server receives request on port 80, and sends a permanent redirection (code 301) to https://my.domain.com.
- Client's user agent receives the response. Given the status code, it sends the same request to https://my.domain.com.
- Server receives request on port 443 and sends back the wanted content.
So, if the request contains sensitive data, between steps 1 and 2, a man-in-the-middle could recover it, non-ciphered, in the request.
If the client uses a web browser, this browser keeps in cache the 301 redirection, and the next time the client send a request using HTTP, it will automatically send it using HTTPS instead.
But, what if the client clears the cache often ? Or use another user agent than a web browser, which does not store the permanent redirection ? Don't we lose the benefit of HTTPS here ?
A concrete example : a REST API, and the requests contain sensitive data. This API can be called from any HTTP client (online, embed in a software or website, standalone).
In this case, could it be better to just disable HTTP support on server level in order to enforce the use of HTTPS ?
Edit 2017-11-14:
sys0dm1n told me about HSTS below. But the security provided by this mechanism depends entirely on the user agent's compliance to the specification.
Edit 2017-11-15:
I edit my post after the first answers I receive, to precise my concern.