The HTTP Content-Security-Policy
(CSP) upgrade-insecure-requests
directive instructs user agents to treat all of a site's insecure URLs (those served over HTTP) as though they have been replaced with secure URLs (those served over HTTPS). This directive is intended for web sites with large numbers of insecure legacy URLs that need to be rewritten.
Note: The upgrade-insecure-requests
directive is evaluated before block-all-mixed-content
and if it is set, the latter is effectively a no-op. It is recommended to set either directive, but not both, unless you want to force HTTPS on older browsers that do not force it after a redirect to HTTP.
The upgrade-insecure-requests
directive will not ensure that users visiting your site via links on third-party sites will be upgraded to HTTPS for the top-level navigation and thus does not replace the Strict-Transport-Security
(HSTS) header, which should still be set with an appropriate max-age
to ensure that users are not subject to SSL stripping attacks.