upgrade-insecure-requests CSP Directive (upgrade-insecure-requests)
Why upgrade-insecure-requests Matters
When migrating a site from HTTP to HTTPS, it is common to have legacy content with hardcoded HTTP URLs for images, scripts, and stylesheets. Finding and updating every HTTP reference across a large site can be time-consuming. upgrade-insecure-requests provides an immediate fix by telling the browser to request the HTTPS version automatically.
This directive only affects resource URLs within the page (images, scripts, stylesheets, etc.) - it does not redirect the page itself. For that, you need server-side HTTP-to-HTTPS redirects and HSTS. upgrade-insecure-requests is a complement to these measures, not a replacement.
The directive is particularly useful for sites with user-generated content where you cannot control the URLs users have entered. If a blog comment contains an HTTP image URL, upgrade-insecure-requests will attempt to load it over HTTPS instead, preventing mixed content warnings.
How to Test for upgrade-insecure-requests
A security audit checks for the upgrade-insecure-requests directive in your CSP. If you have mixed content issues (HTTP resources on HTTPS pages), adding this directive is a quick mitigation while you work on fixing the source URLs.