An HTTPS page that still pulls a script, stylesheet, frame or API call over plain HTTP gives an on-path attacker a way to read or rewrite the page, and modern browsers respond by silently upgrading some of those requests and blocking the rest, which is why so many HTTPS migrations end with broken pages nobody can explain. This guide explains how browsers classify mixed content under the W3C Mixed Content Level 2 specification, what a secure context is and which features need one, and how the CSP upgrade-insecure-requests directive, HSTS and the obsolete block-all-mixed-content directive differ. It ends with a practical method to find and fix mixed content using CSP reporting. It is written for web developers, front-end platform owners and application security engineers finishing or auditing an HTTPS migration. Specification status and browser behaviour were checked in November 2026.
Key takeaways
- Only images, audio and video are upgradable. Browsers following Mixed Content Level 2 rewrite those requests from http to https; everything else (scripts, stylesheets, iframes, fetch, XHR, fonts, srcset images) is blockable and fails with a network error.
- An upgrade never falls back to HTTP. If the HTTPS copy does not exist, the image or video simply does not load, and requests to a bare IP address are blocked rather than upgraded.
- Secure contexts gate powerful features. Service workers, Web Crypto, WebAuthn, Geolocation, the Push and Payment Request APIs and dozens more are exposed only when the page and every ancestor frame are potentially trustworthy.
- upgrade-insecure-requests and HSTS solve different problems. The CSP directive rewrites a page's own subresource URLs; HSTS stops the browser ever using HTTP for your host. Use both, and drop
block-all-mixed-content, which the specification now marks obsolete. - Report first, then enforce. A
Content-Security-Policy-Report-Onlypolicy with adefault-src https:style rule and areport-toendpoint gives you a list of every insecure URL real users hit before you change anything.
What mixed content is
Mixed content is any resource requested over an insecure scheme from a document that was itself delivered securely. The page arrived over TLS, so the browser shows it as secure, but some of the content that makes up the page did not. The W3C specification checks this for the top-level document and for every ancestor frame: if a secure page frames another secure page that then loads http:// content, that request is still mixed and is treated as such.
The risk depends on what the resource can do. A script loaded over HTTP runs with the full authority of the page, so anyone on the network path (a hostile Wi-Fi hotspot, a compromised router, an ISP injecting content) can replace it and take over the session, read form fields or rewrite links. This is the adversary-in-the-middle position described in MITRE ATT&CK T1557 Adversary-in-the-Middle. A replaced image is less dangerous but can still mislead users or leak which pages they visit.
Two related cases are easy to miss:
- Mixed downloads: a download started from a secure page but fetched over HTTP. The specification says these are not upgraded; the browser aborts them, although the bytes may already have crossed the network. MDN notes that browsers which block them usually warn the user and offer to keep or discard the file.
- Insecure form actions: a form on an HTTPS page that posts to an
http://URL. The specification lets browsers warn on these and treat them as blockable even at top level, so never rely on such a form working.
Older documentation talks about "active" and "passive" or "blockable" and "optionally blockable" content. Mixed Content Level 2 replaced that model: the old optionally blockable set became the much smaller upgradable set, and everything else is blockable.
Upgradable vs blockable content
The current specification is a W3C Candidate Recommendation Draft dated 23 February 2023. It defines upgradable content narrowly and makes everything else blockable. Browsers autoupgrade the first group and block the second.
| Resource | Category | Browser handling on an HTTPS page | Fix |
|---|---|---|---|
<img src>, CSS background-image and border-image (host name, not IP) | Upgradable | Rewritten to https; fails if the HTTPS copy is missing | Change URL to https or relative path |
<audio>, <video> and their <source> elements | Upgradable | Rewritten to https; fails if unavailable | Host media on HTTPS |
<img> with srcset or inside <picture> | Blockable | Blocked | Rewrite every candidate URL |
<img crossorigin> (CORS request) | Blockable | Force-failed by the specification | Serve over HTTPS with CORS headers |
Any upgradable type addressed by IP (http://192.0.2.10/x.png) | Blockable | Blocked, not upgraded | Use a host name with a valid certificate |
<script src>, <link href> stylesheets, web fonts, @font-face | Blockable | Blocked | Self-host or use the provider's HTTPS URL |
<iframe src>, <object data> | Blockable | Blocked | Frame HTTPS content only |
fetch(), XMLHttpRequest, navigator.sendBeacon | Blockable | Blocked with a network error | Move APIs to HTTPS, fix base URLs in config |
Download link to http:// | Mixed download | Aborted, usually with a user warning | Serve files over HTTPS |
Chrome introduced this behaviour in stages: the Chromium team announced in October 2019 a per-site setting to unblock mixed content in Chrome 79, autoupgrade of mixed audio and video in Chrome 80, and autoupgrade of mixed images, later delayed to Chrome 84 or later. MDN now lists mixed content handling as Baseline widely available, so assume every current major browser upgrades the upgradable set and blocks the rest. Users can still override blocking in site settings, which the specification allows, so a page that "works on my machine" may only work because a tester once clicked through.
Secure contexts and the features that require them
A secure context is a window or worker that meets minimum standards of authentication and confidentiality. The W3C Secure Contexts specification (Candidate Recommendation Draft, 10 November 2023) defines it through the idea of a potentially trustworthy origin:
- Trustworthy:
httpsandwssorigins; loopback addresses127.0.0.0/8and::1;localhostand*.localhostwhere the browser resolves them to loopback;about:blank,about:srcdocanddata:URLs; origins a developer has configured as trusted for testing. - Usually trustworthy:
file:URLs (the specification says SHOULD, so a hardened browser may exclude them) and vendor schemes such as extension URLs. - Not trustworthy: opaque origins and plain
httpon any other host. Domain and port make no difference.
The ancestor rule matters most in practice. A framed document is a secure context only if it came from a trustworthy origin and its embedder is also a secure context, so an HTTPS widget framed by an HTTP page loses every secure-only feature. Dedicated workers inherit from their owner, shared workers from their creator, and service workers are always secure and can only be registered by secure clients. Code can check self.isSecureContext at runtime, and specification authors mark interfaces with the [SecureContext] IDL attribute so they simply do not exist elsewhere.
The localhost exemption is why development often works and staging breaks: http://localhost:3000 is a secure context, but http://staging.internal is not, so service workers, WebAuthn and the clipboard API vanish the moment the app moves to an internal HTTP host. Put staging behind HTTPS with an internal CA rather than adding browser flags. See the ACME and Automated Certificate Management Guide.
| Area | Examples restricted to secure contexts (MDN list, March 2026) |
|---|---|
| Identity and credentials | Web Authentication API, Credential Management API, WebOTP API, Payment Request API, Web-based Payment Handler API |
| Cryptography and storage | Web Crypto API, Storage API, Cookie Store API, File System API, Web Locks API, Shared Storage API |
| Offline and background | Service Workers, Background Fetch, Background Synchronization, Push API, Notifications API, Content Index API |
| Devices and sensors | Geolocation, Generic Sensor, Device Orientation and Motion, Web Bluetooth, WebUSB, WebHID, Web NFC, Web MIDI, Gamepad, WebXR |
| Media and capture | getUserMedia(), Screen Capture, Encrypted Media Extensions, Audio Output Devices, WebCodecs |
| Other | Async Clipboard, Reporting API, WebGPU, WebTransport, Web Share, Screen Wake Lock, Badging, Idle Detection, Window Management |
The specification is clear about one limit: secure and non-secure views of the same origin are not fully isolated, so data can still pass between them through localStorage, BroadcastChannel and storage events. Do not treat "secure context" as a substitute for serving the whole origin over HTTPS. Secure-only cookies are a separate control; see the Cookie Security Guide.
upgrade-insecure-requests and HSTS
Three mechanisms are often confused. They work at different layers and you normally want two of them.
| Mechanism | What it does | What it does not do | Status |
|---|---|---|---|
CSP upgrade-insecure-requests | Rewrites the page's own http: subresource requests (including blockable ones and ws:) to https: before they leave the browser; also upgrades same-origin navigations and form submissions; inherited by nested frames and workers | Does not upgrade third-party links into your site, has no HTTP fallback, ignored in Report-Only policies | W3C Candidate Recommendation (2015), widely implemented |
HSTS (Strict-Transport-Security) | Tells the browser to use HTTPS for every future request to the host (and subdomains with includeSubDomains), removing the HTTP fallback attackers exploit | Does nothing for third-party hosts your page loads from; first visit is unprotected unless preloaded | RFC 6797 |
CSP block-all-mixed-content | Blocked all mixed content including the old optionally blockable set | Redundant now that upgradable content is upgraded and everything else blocked; does nothing when upgrade-insecure-requests is present | Obsolete in Mixed Content Level 2; deprecated on MDN |
Decision guidance:
- Large legacy site or CMS with hard-coded
http://links in stored content: sendupgrade-insecure-requestsas soon as every referenced host supports HTTPS, then clean the content over time. The specification was written for exactly this migration case. - Modern application you build from source: fix the URLs at source, use relative or
https://URLs, and treatupgrade-insecure-requestsas a safety net rather than the fix. - Any site: deploy HSTS on the host itself. The directive protects what the page loads; HSTS protects how the user reaches the page. See the HSTS and HSTS Preload guide.
- You want to block, not upgrade, a resource class: restrict the relevant fetch directive to HTTPS, for example
img-src https:, instead of the obsolete directive.
Browsers that support the directive also send an Upgrade-Insecure-Requests: 1 request header. Servers can use it to redirect an HTTP request to HTTPS (the specification suggests a 307 with Vary: Upgrade-Insecure-Requests), which is a useful hint but no replacement for a blanket redirect plus HSTS. For the wider header set, see the Security Headers Guide and the Content Security Policy Guide.
Finding and fixing mixed content
The fastest reliable inventory comes from real browsers via CSP reporting, backed by a crawl and a source search. Work through it in this order.
- Search the source and content stores. Grep templates, front-end bundles, configuration (API base URLs, CDN hosts, analytics snippets) and CMS database fields for
http://. Database content and third-party tag managers are where most stragglers live. - Deploy a report-only policy. Send
Content-Security-Policy-Report-Only: default-src https: 'unsafe-inline' 'unsafe-eval'; report-to csp-endpointwith a matchingReporting-Endpointsheader. This reports every non-HTTPS load without breaking anything; tighten or drop the unsafe keywords once your main CSP exists. Note thatupgrade-insecure-requestsitself is ignored in report-only mode, and that reports show the original insecure URL. - Triage the reports. CSP Level 3 violation reports carry
documentURL,blockedURLandeffectiveDirective. Group by blocked host and directive, then by page. Sort fixes by request volume, as the specification advises. - Fix by host. First-party hosts: move to HTTPS and rewrite links. Third-party hosts: switch to their HTTPS endpoint, self-host the asset, or remove it. A third party with no HTTPS option is a supply chain risk in its own right.
- Turn on upgrade-insecure-requests in enforcing CSP. Pilot on one section of the site, watch error rates and broken-image reports for a week, then widen. Rollback is removing the directive from the header at the edge.
- Add HSTS and redirects. Redirect port 80 to HTTPS on the same host, then ramp HSTS
max-ageup in stages. - Keep the report-only policy running. New content and new tags will reintroduce
http://links; continuous reporting catches them.
Testing: the browser developer console logs each upgraded and blocked request. MDN also suggests turning on your browser's option to block all mixed content and checking pages still work, plus crawling the site with a link checker. Add an automated check in CI that fails a build on new http:// references in templates. For scripts that must come from a CDN, pair HTTPS with integrity checks; see the Subresource Integrity (SRI) Guide.
Small vs large estates: a small site can usually fix every URL by hand in a day and skip report-only. A large estate with many teams, a CMS and dozens of tag manager containers should treat this as a programme: central reporting endpoint, owner per host, and a dashboard.
Detection and measurement
- Mixed content reports per day: count of CSP reports with an
http:blockedURL, trending to zero. - Distinct insecure hosts: number of unique hosts still requested over HTTP, with an owner for each.
- Pages with blocked resources: share of crawled pages logging any blocked request in the console.
- HSTS coverage: percentage of public hosts sending HSTS with a
max-ageof at least one year. - Secure-context failures: client errors where
isSecureContextis false or a secure-only API is undefined, a sign that an app is being framed or served insecurely.
Framework mapping
| Framework | Reference | How it applies |
|---|---|---|
| NIST SP 800-53 Rev 5 | SC-8 Transmission Confidentiality and Integrity; SC-23 Session Authenticity | Every resource of an authenticated page travels over TLS |
| NIST CSF 2.0 | PR.DS-02; PR.PS-01 | Data in transit protected; header and CSP configuration managed |
| OWASP ASVS 5.0 | V3.4.1 (HSTS); V3.4.3 (CSP); V3.1.1 (documented browser security features) | Verification requirements for headers and policy |
| CIS Controls v8.1 | Control 16 Application Software Security | Secure development and configuration of web applications |
| ISO/IEC 27001:2022 | A.8.24 Use of cryptography; A.8.28 Secure coding | Encryption in transit and safe coding standards |
| MITRE ATT&CK v20 | T1557 Adversary-in-the-Middle; T1185 Browser Session Hijacking | Threats that insecure subresources enable |
Common failure patterns
- Images break after the migration: the browser upgraded
http://cdn.example.com/a.pngbut the CDN has no certificate for that name. Upgrades never fall back, so the fix is HTTPS on the asset host, not a browser exception. - Responsive images missed: teams fix
srcbut leavesrcsetor<picture>candidates on HTTP, which are blockable, so some devices see blank images while desktops look fine. - Relying on upgrade-insecure-requests for top-level safety: the directive does not protect users who arrive via an
http://link from another site. Without HSTS, the first request is still exposed to stripping. - Staging on plain HTTP: service workers, WebAuthn and clipboard features work on localhost and in production but fail on an HTTP staging host because it is not a secure context, so bugs reach production untested.
- Keeping block-all-mixed-content: it adds nothing in current browsers, does nothing alongside
upgrade-insecure-requests, and gives a false sense of a control. - One-off clean-up with no monitoring: marketing tags, embeds and CMS content reintroduce HTTP links within months unless report-only CSP stays on.
Practitioner checklist
- Search templates, bundles, configuration and CMS content for
http://and assign an owner to each host found. - Deploy a report-only CSP that flags non-HTTPS loads, with a
report-toendpoint, before changing behaviour. - Move every first-party asset host to HTTPS with automated certificate renewal.
- Replace or self-host third-party assets that have no HTTPS endpoint.
- Fix
srcset,<picture>, fonts and IP-addressed URLs, which are blocked rather than upgraded, and move WebSockets towss://. - Add
upgrade-insecure-requeststo the enforcing CSP after a pilot, and removeblock-all-mixed-content. - Deploy HSTS on every public host and redirect port 80 to HTTPS.
- Run staging and test environments on HTTPS so secure-context features behave as in production.
- Fail CI builds on new
http://references and keep CSP reporting on permanently.
Standards and references
- W3C: Mixed Content Level 2
- W3C: Secure Contexts
- W3C: Upgrade Insecure Requests
- W3C: Content Security Policy Level 3 (Editor's Draft)
- MDN: Mixed content
- MDN: Features restricted to secure contexts
- MDN: CSP block-all-mixed-content
- Chromium Blog: No More Mixed Messages About HTTPS
Related NHI Mgmt Group resources: Content Security Policy Guide · HSTS and HSTS Preload · Security Headers Guide · Subresource Integrity (SRI) Guide · How TLS Works Guide