Mixed content

On this page 7

Mixed content is the situation in which a page delivered over secure HTTPS loads subresources over insecure HTTP, such as scripts, stylesheets, images, media, fonts or API calls. On the Web, this breaks the guarantee that everything the user sees and runs came encrypted and unaltered from the origin, because any HTTP request can be read or modified by an attacker on the network path.

Modern browser technologies treat mixed content as a security defect. Browsers block most insecure requests by default, automatically upgrade others to HTTPS and flag the page in the address bar, so fixing mixed content is a standard step in every migration from HTTP to HTTPS.

Why mixed content undermines HTTPS

HTTPS protects a page through TLS encryption and server authentication, but that protection covers only the requests made over TLS. When the HTML document is secure and a script arrives over HTTP, a man-in-the-middle attacker on public Wi-Fi or a compromised router can replace that script and gain full control of the page, including its cookies, forms and displayed content.

The risk depends on what the insecure resource can do. A script runs with the privileges of the secure origin, while an image can at most be swapped or observed. This difference is the basis of the browser rules described in the W3C Mixed Content specification.

Insecure resourceWhat an attacker can doSeverity
ScriptExecute arbitrary code in the secure originCritical
StylesheetAlter layout, hide warnings, exfiltrate data via CSS selectorsHigh
IframeInject a phishing frame inside a trusted pageHigh
Fetch or XHR requestRead or modify application dataCritical
ImageReplace the picture, track the visitModerate
Audio or videoSwap media, reveal what the user watchesModerate
Attack possibilities by resource type

Active and passive mixed content

The Mixed Content specification divides insecure resources into blockable and upgradeable content, often called active and passive mixed content. Blockable content can affect the whole page, so browsers refuse to load it. Upgradeable content has limited reach, so browsers rewrite its URL to HTTPS and load it only if the secure version exists.

CategoryTypical elementsDefault browser behavior
Blockable (active)script, link stylesheet, iframe, fetch, XHR, WebSocket over wsBlocked, console error logged
Upgradeable (passive)img, audio, video, sourceRewritten to HTTPS, fails if unavailable
Insecure form actionform posting to an http URLWarning before submission or blocked
Insecure downloadsFile links over HTTP from a secure pageWarning or block in Chromium-based browsers
How current browsers handle each category

Older browsers displayed passive mixed content with only a warning icon instead of the padlock. Since about 2020, Chromium, Gecko and WebKit have converged on autoupgrade plus blocking, which means that a missing HTTPS version of an image now results in a broken image rather than an insecure one.

Mixed content rules work alongside other browser security mechanisms, and they are easy to confuse. The mixed content check looks only at the scheme of each subresource, whereas the same-origin policy and CORS govern which origins may read each other’s data.

MechanismQuestion it answersRelation to mixed content
Mixed content blockingIs this subresource fetched securelyCore subject of this page
Same-origin policyMay this origin read another origin’s dataIndependent; secure cross-origin loads are allowed
CORSHas the server permitted cross-origin accessCannot override mixed content blocking
HSTSMust this host always use HTTPSPrevents insecure loads to listed hosts
upgrade-insecure-requestsShould HTTP URLs be rewritten automaticallyCSP directive that removes most mixed content
Mixed content compared with neighboring concepts

Finding and fixing mixed content

The reliable fix is to serve every resource over HTTPS and reference it correctly. Detection starts in the developer tools console, where browsers log each blocked or upgraded request, and continues with crawlers that scan all pages, because mixed content often hides in old posts, templates and third-party embeds.

  1. Enable HTTPS on every host that serves assets, including CDNs and media subdomains.
  2. Replace hard-coded HTTP URLs in templates, databases and configuration with HTTPS or relative paths.
  3. Add the Content-Security-Policy directive upgrade-insecure-requests as a safety net for legacy URLs.
  4. Use Content-Security-Policy-Report-Only to collect reports of remaining insecure requests before enforcing stricter rules.
  5. Enable HSTS once all content is secure, so browsers never request the site over HTTP again.

Protocol-relative URLs that start with two slashes were once recommended, but they are now considered an outdated pattern. Explicit HTTPS references are clearer and avoid surprises when pages are saved locally or rendered in unusual contexts.

Common mistakes and symptoms

Most mixed content incidents appear after a site moves to HTTPS or when external content is embedded. The symptoms are often visual rather than obvious security errors, which makes the cause easy to overlook.

SymptomLikely causeFix
Page loads without stylingStylesheet linked over HTTPUpdate the link to HTTPS
Interactive features stop workingScript or API endpoint over HTTPServe the endpoint over HTTPS
Broken images in old articlesAbsolute HTTP URLs stored in the databaseRun a search and replace on stored content
Embedded widget is emptyThird-party iframe without HTTPSSwitch provider or use its HTTPS embed
Padlock missing or warning shownInsecure form action or passive resourceCorrect the URL and retest
Symptoms, causes and fixes

A frequent misconception is that a valid TLS certificate alone makes a page secure. The certificate protects only the connections that use it, so a page with a perfect certificate can still be fully compromised through one insecure script.

Understanding it simply

Mixed content is like a sealed envelope that contains an unsealed note from someone else. The main letter arrives safely, but anyone along the way could have read or changed the loose note before it was slipped inside.

When a secure website pulls in even one picture or piece of code through an unprotected connection, that piece becomes the weak point. Browsers therefore block or upgrade those pieces automatically, and website owners fix the problem by making sure every part of the page travels over the secure connection.

Applied in practice

A small online shop moves from HTTP to HTTPS after installing a free certificate. The home page shows the padlock, yet customers report that the checkout button does nothing. The developer opens the browser console and finds that the payment script is loaded from an HTTP address hard-coded in an old theme file, and the browser has blocked it.

A crawl of the full site also reveals about 1,200 product images with absolute HTTP URLs stored in the database. The developer updates the theme, runs a database search and replace, and adds the upgrade-insecure-requests directive as a fallback. After a week with report-only monitoring shows no remaining insecure requests, HSTS is enabled.

The result is a fully secure storefront with working checkout, consistent padlock indicators in every browser and no broken product images.