Find Mixed Content on HTTPS Pages Across Your Sitemap with Python (Standard Library Only): Insecure Forms, Downloads, CSV Report
Moving a site to HTTPS is usually one afternoon of certificates and redirects. Getting every page clean takes longer. An old blog post still embeds a video with http://. A theme loads a web font from an http:// URL. A wh
Moving a site to HTTPS is usually one afternoon of certificates and redirects. Getting every page clean takes longer. An old blog post still embeds a video with http://. A theme loads a web font from an http:// URL. A wholesale price list is linked with download from a file server that never got a certificate. A newsletter form still posts to http://. The page loads with a padlock, the browser quietly blocks or upgrades a few requests, and nobody notices until a font is missing, an embed is blank or a customer asks why the form looks broken.
This post builds a mixed content auditor in Python using only the standard library (urllib, urllib.robotparser, html.parser, xml.etree, ssl, ipaddress, csv, re, concurrent.futures). It reads your sitemap or sitemap index, fetches every page, and lists every http:// reference the page would load, submit or download, sorted the way MDN describes browser behaviour: blockable (scripts, stylesheets, iframes, srcset, fonts and more), upgradable (<img src>, <audio>, <video>), and the special case of an image on a bare IP address. It also flags insecure form actions, mixed downloads, http:// links back to your own site, http:// URLs in the sitemap itself, and notes when a page sets upgrade-insecure-requests.
MDN's Mixed content page (showing "last modified on Aug 15, 2026") and MDN's CSP: upgrade-insecure-requests page (showing "last modified on Nov 30, 2025") were opened on 19 Nov 2026, and every statement attributed to them below comes from those pages. The output in this post comes from a small fictional site ("Harbor Tea Co.") served over HTTPS on localhost with a self-signed certificate, built for this article with planted problems. Appie free-tool descriptions are as of 19 Nov 2026, checked on each tool's page that day.
Disclosure: Appie.run publishes this article. Two free tools mentioned near the end are ours. The script does not depend on them.
Where this fits
This is another script in a small standard-library series that reads a sitemap and checks one thing per page. An earlier one found broken links and redirect chains, which catches http:// URLs that redirect. Another audited canonical tags and noindex, which is where an http:// canonical usually shows up after a migration. This one looks at what each HTTPS page pulls in. Same approach throughout: parse what the server returns, report what is there, and leave the judgment to a person.
What MDN actually says (and what it does not)
What mixed content is. MDN defines it as "securely loaded web pages that use resources to be fetched via HTTP or another insecure protocol." The risk is that "any resources that are sent insecurely can be viewed, possibly revealing sensitive information, and/or modified by an attacker." It adds that "Scripts are particularly dangerous because they can modify any aspect of the page, but all types of resources have some risk."
What browsers do about it. "Browsers mitigate the risks of mixed content by auto-upgrading image, video, and audio mixed content requests from HTTP to HTTPS, and block insecure requests for all other resource types." Upgradable content is defined by a short list: <img> with src (but not srcset or <picture>), CSS image properties such as background-image, and <audio>, <video> and <source> for media. Blockable content is "all mixed content that is not upgradable," and MDN's non-exhaustive list includes <script src>, <link href> (including stylesheets), <iframe src>, fetch() and XMLHttpRequest, "All cases in CSS where a <url> value is used (@font-face, cursor, background-image, and so forth)," <object data>, <img> via srcset or <picture>, and web fonts.
The IP address exception. "Mixed content requests that would otherwise be upgraded are blocked if the URL's host is an IP address rather than a domain name." So <img src="http://example.com/image.png"> is upgraded, but the same tag pointing at an IP address is blocked.
Downloads. A mixed download is "a resource download from a secure context over an insecure connection," and MDN's example is an <a href="http://..." download> on an HTTPS page. "Browsers are expected to block mixed downloads, and secure sites should not include them."
Links are not mixed content. MDN says "navigation requests from a secure context that target insecure target top-level browsing contexts are not considered mixed content." A plain http:// link is a different, smaller problem: the visitor leaves HTTPS, and on your own site it costs a redirect.
upgrade-insecure-requests. The CSP 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." It is "intended for websites with large numbers of insecure legacy URLs that need to be rewritten." Two warnings on the same page matter for an audit: "if the requested resource is not actually available via HTTPS, the request will fail without any fallback to HTTP," and navigational links to third-party sites are not upgraded. It also "does not replace the Strict-Transport-Security (HSTS) header."
The fix. MDN's advice: "Serve all content from your domain as HTTPS," make references to your own resources relative or HTTPS, and use HTTPS versions of third-party resources where available.
What MDN does not settle cleanly is CSS images: background-image appears in its upgradable list and again in its blockable list ("All cases in CSS where a <url> value is used"). The script gives CSS url() its own flag, css_url, and treats it as high severity. Either way, the fix is the same: change the URL. Forms are also not on MDN's mixed content page, so the insecure_form_action flag is my own call: a form on an HTTPS page that submits to http:// sends whatever the visitor typed over an unencrypted connection, which is worth fixing whatever the browser does about it.
How the audit works
-
Sitemap URLs. It reads a
urlsetor a sitemap index (recursively, gzip supported) and keeps every<loc>.robots.txtis respected for page fetches. Any<loc>that starts withhttp://is flagged assitemap_http_url, and the page is still fetched so you can see where it redirects. -
HTTPS only. Mixed content only exists on secure pages, so a page whose final URL (after redirects) is still
http://is reported asserved_over_httpand not parsed further. -
References per page. It parses the HTML and collects every
http://URL in the attributes a browser would request:img srcandsrcset,picture > source srcset,audio,video(srcandposter) and theirsourcechildren,script src,link hreffor stylesheet, preload, modulepreload, prefetch, icon and manifest,iframe src,object data,embed src,form action,a hrefwithdownload, inlinestyle="...url(http://...)", andurl(),@importand@font-faceinside<style>blocks. -
Classification. Each reference is labelled with MDN's categories, the IP host exception and the extra flags above, then given a severity: high if a browser blocks it or it leaks data (blockable, CSS
url(), blocked IP host, insecure form, mixed download), medium if a browser upgrades it (it still fails if the HTTPS version does not exist), low for plainhttp://links. -
CSP note. If the page sets
upgrade-insecure-requestsin a<meta>tag or theContent-Security-Policyresponse header, every row for that page getscsp_upgrade=yes. The references are still listed, because MDN says the upgraded request fails if the HTTPS version is missing. -
Optional HTTPS check.
--check-httpssends aHEADrequest to thehttps://version of every flagged URL and records the status (orunreachable,timeout,tls_error) in thehttps_versioncolumn, so you know which ones you can fix with a find and replace.
What the script flags
| Flag | Severity | Meaning | What to do |
|---|---|---|---|
blockable |
high | Script, stylesheet, iframe, srcset, font, @import, object or embed over http://
|
Switch to the HTTPS URL, self-host, or remove |
css_url |
high |
url(http://...) in an inline style or <style> block |
Switch to HTTPS or a relative path |
blocked_ip_host |
high | Upgradable element whose host is an IP address | Serve it from a hostname with a certificate |
insecure_form_action |
high | Form on an HTTPS page posts to http://
|
Point the action at HTTPS or a relative path |
mixed_download |
high |
<a download> pointing at http://
|
Host the file over HTTPS |
upgradable |
medium |
img src, audio, video or media source over http://
|
Switch to HTTPS; check it exists there |
sitemap_http_url |
medium | The sitemap lists an http:// URL |
List the canonical HTTPS URL instead |
served_over_http |
high | The page itself ends up on http://
|
Fix the redirect to HTTPS |
http_internal_link / http_external_link
|
low | Plain <a href="http://...">
|
Use HTTPS or relative links for your own pages |
redirected / http_404 / blocked_by_robots / not_html / unreachable
|
info | Page-level fetch notes | Check the page or the sitemap entry |
clean |
ok | No http:// references found |
Nothing to do |
Three limits to know up front. The script reads only the HTML your server returns, so http:// requests made by JavaScript at runtime (fetch(), tag managers, ad scripts) are not in the report; MDN's suggestion of checking the browser's developer console for mixed content warnings covers those. It does not download external stylesheets to look for url() inside them, only inline styles and <style> blocks. And markup inside <template> and <noscript> is parsed like any other, so an http:// reference there is reported even if a browser would not request it, while anything inside HTML comments is ignored.
The script
Save as mixed_content_audit.py. Python 3.9 or later.
#!/usr/bin/env python3
"""Find mixed content on HTTPS pages listed in a sitemap (standard library only).
Usage:
python3 mixed_content_audit.py https://example.com/sitemap.xml
python3 mixed_content_audit.py https://example.com/sitemap.xml --check-https --out mixed.csv
"""
import argparse
import csv
import gzip
import ipaddress
import re
import ssl
import sys
import urllib.error
import urllib.request
import urllib.robotparser
import xml.etree.ElementTree as ET
from collections import Counter
from concurrent.futures import ThreadPoolExecutor
from html.parser import HTMLParser
from urllib.parse import urljoin, urlsplit
UA = "mixed-content-audit/1.0 (+standard library script)"
SM_NS = "{http://www.sitemaps.org/schemas/sitemap/0.9}"
CSS_URL = re.compile(r"""url\(\s*['"]?(http://[^'")\s]+)""", re.I)
CSS_IMPORT = re.compile(r"""@import\s+(?:url\()?\s*['"]?(http://[^'")\s;]+)""", re.I)
FONT_FACE = re.compile(r"@font-face\s*{[^}]*}", re.I | re.S)
CSP_UPGRADE = re.compile(r"upgrade-insecure-requests", re.I)
# What MDN's "Mixed content" page lists as blockable when loaded over http://
BLOCKABLE_LINK_RELS = {"stylesheet", "preload", "modulepreload", "prefetch", "icon",
"shortcut", "apple-touch-icon", "manifest"}
# ---------- fetching ----------
def make_context(cafile):
return ssl.create_default_context(cafile=cafile) if cafile else ssl.create_default_context()
def fetch(url, ctx, timeout=15, method="GET"):
req = urllib.request.Request(url, headers={"User-Agent": UA}, method=method)
try:
with urllib.request.urlopen(req, timeout=timeout, context=ctx) as r:
body = r.read() if method == "GET" else b""
if body[:2] == b"\x1f\x8b":
body = gzip.decompress(body)
return r.status, r.geturl(), {k.lower(): v for k, v in r.headers.items()}, body, ""
except urllib.error.HTTPError as e:
return e.code, url, {}, b"", f"http_{e.code}"
except (TimeoutError, OSError) as e: # DNS, refused, TLS, timeout
reason = getattr(e, "reason", e)
if isinstance(reason, TimeoutError) or "timed out" in str(reason):
return 0, url, {}, b"", "timeout"
if isinstance(reason, ssl.SSLError):
return 0, url, {}, b"", "tls_error"
return 0, url, {}, b"", "unreachable"
# ---------- sitemap ----------
def sitemap_urls(url, ctx, seen=None):
seen = seen if seen is not None else set()
if url in seen:
return []
seen.add(url)
status, _, _, body, err = fetch(url, ctx)
if status != 200:
sys.exit(f"Could not read sitemap {url}: {err or status}")
root = ET.fromstring(body)
if root.tag == SM_NS + "sitemapindex":
out = []
for loc in root.iter(SM_NS + "loc"):
out += sitemap_urls(loc.text.strip(), ctx, seen)
return out
return [loc.text.strip() for loc in root.iter(SM_NS + "loc") if loc.text]
# ---------- HTML ----------
class Collector(HTMLParser):
"""Collect every http:// reference a browser would request (or submit/download) from the page."""
def __init__(self):
super().__init__(convert_charrefs=True)
self.refs = [] # (element, attribute, url, kind)
self.csp_upgrade = False
self.in_picture = 0
self.media_parent = [] # stack of audio/video
self.in_style = False
self.style_text = []
def add(self, el, attr, url, kind):
if url and url.strip().lower().startswith("http://"):
self.refs.append((el, attr, url.strip(), kind))
def handle_starttag(self, tag, attrs):
a = {k: (v or "") for k, v in attrs}
if tag == "picture":
self.in_picture += 1
if tag in ("audio", "video"):
self.media_parent.append(tag)
if tag == "style":
self.in_style = True
if tag == "meta" and a.get("http-equiv", "").lower() == "content-security-policy":
if CSP_UPGRADE.search(a.get("content", "")):
self.csp_upgrade = True
if tag == "img":
self.add("img", "src", a.get("src"), "upgradable")
for part in a.get("srcset", "").split(","):
self.add("img", "srcset", part.strip().split(" ")[0], "blockable")
elif tag == "source":
if self.in_picture:
for part in a.get("srcset", "").split(","):
self.add("picture>source", "srcset", part.strip().split(" ")[0], "blockable")
if self.media_parent:
self.add(self.media_parent[-1] + ">source", "src", a.get("src"), "upgradable")
elif tag in ("audio", "video"):
self.add(tag, "src", a.get("src"), "upgradable")
if tag == "video":
self.add("video", "poster", a.get("poster"), "upgradable")
elif tag == "script":
self.add("script", "src", a.get("src"), "blockable")
elif tag == "link":
rels = set(a.get("rel", "").lower().split())
if rels & BLOCKABLE_LINK_RELS:
self.add("link[rel=" + " ".join(sorted(rels)) + "]", "href", a.get("href"), "blockable")
elif tag == "iframe":
self.add("iframe", "src", a.get("src"), "blockable")
elif tag == "object":
self.add("object", "data", a.get("data"), "blockable")
elif tag == "embed":
self.add("embed", "src", a.get("src"), "blockable")
elif tag == "form":
self.add("form", "action", a.get("action"), "insecure_form")
elif tag == "a" and "download" in a:
self.add("a[download]", "href", a.get("href"), "mixed_download")
elif tag == "a":
self.add("a", "href", a.get("href"), "http_link")
if "style" in a:
for m in CSS_URL.finditer(a["style"]):
self.add(tag + "[style]", "url()", m.group(1), "css_url")
def handle_endtag(self, tag):
if tag == "picture" and self.in_picture:
self.in_picture -= 1
if tag in ("audio", "video") and self.media_parent:
self.media_parent.pop()
if tag == "style":
self.in_style = False
self.scan_css("".join(self.style_text))
self.style_text = []
def handle_data(self, data):
if self.in_style:
self.style_text.append(data)
def scan_css(self, css):
done = set()
for block in FONT_FACE.findall(css):
for m in CSS_URL.finditer(block):
self.add("style @font-face", "url()", m.group(1), "blockable")
done.add(m.group(1))
for m in CSS_IMPORT.finditer(css):
self.add("style @import", "url()", m.group(1), "blockable")
done.add(m.group(1))
for m in CSS_URL.finditer(css):
if m.group(1) not in done:
self.add("style", "url()", m.group(1), "css_url")
def is_ip(host):
try:
ipaddress.ip_address(host)
return True
except ValueError:
return False
def same_site(a, b):
strip = lambda h: (h or "").lower().removeprefix("www.")
return strip(a) == strip(b)
def classify(kind, url, page_host):
"""Return (flag, severity). Severity: high = browser blocks it, medium = worth fixing, low = note."""
host = urlsplit(url).hostname or ""
if kind == "upgradable":
if is_ip(host):
return "blocked_ip_host", "high"
return "upgradable", "medium"
if kind == "blockable":
return "blockable", "high"
if kind == "css_url":
return "css_url", "high"
if kind == "insecure_form":
return "insecure_form_action", "high"
if kind == "mixed_download":
return "mixed_download", "high"
if kind == "http_link":
return ("http_internal_link", "low") if same_site(host, page_host) else ("http_external_link", "low")
return kind, "low"
# ---------- audit ----------
def audit_page(url, ctx, robots):
rows = []
if robots and not robots.can_fetch(UA, url):
return [dict(page=url, flag="blocked_by_robots", severity="info")]
if urlsplit(url).scheme == "http":
rows.append(dict(page=url, flag="sitemap_http_url", severity="medium"))
status, final, headers, body, err = fetch(url, ctx)
if status != 200:
return rows + [dict(page=url, flag=err or f"http_{status}", severity="info")]
if urlsplit(final).scheme != "https":
return rows + [dict(page=url, flag="served_over_http", severity="high", url=final)]
ctype = headers.get("content-type", "")
if "html" not in ctype:
return rows + [dict(page=url, flag="not_html", severity="info")]
if final != url:
rows.append(dict(page=url, flag="redirected", severity="info", url=final))
p = Collector()
p.feed(body.decode("utf-8", "replace"))
csp = p.csp_upgrade or bool(CSP_UPGRADE.search(
headers.get("content-security-policy", "")))
page_host = urlsplit(final).hostname
for el, attr, ref, kind in p.refs:
absolute = urljoin(final, ref)
flag, sev = classify(kind, absolute, page_host)
rows.append(dict(page=final, element=el, attribute=attr, url=absolute, flag=flag,
severity=sev, csp_upgrade="yes" if csp else "no"))
if not p.refs:
rows.append(dict(page=final, flag="clean", severity="ok", csp_upgrade="yes" if csp else "no"))
return rows
def https_status(url, ctx, cache):
target = "https://" + url.split("://", 1)[1]
if target not in cache:
status, _, _, _, err = fetch(target, ctx, timeout=5, method="HEAD")
cache[target] = str(status) if status else err
return cache[target]
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("sitemap")
ap.add_argument("--out", default="mixed_content.csv")
ap.add_argument("--workers", type=int, default=4)
ap.add_argument("--cafile", help="extra CA bundle (e.g. a self-signed test server)")
ap.add_argument("--check-https", action="store_true",
help="HEAD the https:// version of every http:// reference")
ap.add_argument("--hide-links", action="store_true", help="drop plain http:// <a> links from the report")
args = ap.parse_args()
ctx = make_context(args.cafile)
split = urlsplit(args.sitemap)
robots = urllib.robotparser.RobotFileParser()
status, _, _, body, _ = fetch(f"{split.scheme}://{split.netloc}/robots.txt", ctx)
robots.parse(body.decode("utf-8", "replace").splitlines() if status == 200 else [])
urls = list(dict.fromkeys(sitemap_urls(args.sitemap, ctx)))
with ThreadPoolExecutor(args.workers) as ex:
results = list(ex.map(lambda u: audit_page(u, ctx, robots), urls))
rows = [r for page_rows in results for r in page_rows]
if args.hide_links:
rows = [r for r in rows if r["flag"] not in ("http_internal_link", "http_external_link")]
if args.check_https:
cache = {}
for r in rows:
if r.get("url", "").startswith("http://"):
r["https_version"] = https_status(r["url"], ctx, cache)
fields = ["page", "element", "attribute", "url", "flag", "severity", "csp_upgrade", "https_version"]
with open(args.out, "w", newline="") as f:
w = csv.DictWriter(f, fieldnames=fields, extrasaction="ignore")
w.writeheader()
w.writerows(rows)
pages_with_issues = {r["page"] for r in rows if r["severity"] in ("high", "medium")}
print(f"Sitemap URLs: {len(urls)} pages with mixed content or http issues: {len(pages_with_issues)}")
print("By flag:")
for flag, n in Counter(r["flag"] for r in rows).most_common():
print(f" {flag:<22} {n}")
print("\nHigh severity:")
for r in rows:
if r["severity"] == "high":
extra = f" [https: {r['https_version']}]" if r.get("https_version") else ""
csp = " (page has upgrade-insecure-requests)" if r.get("csp_upgrade") == "yes" else ""
print(f" {urlsplit(r['page']).path or '/':<22} {r.get('element',''):<28} {r.get('url','')}{extra}{csp}")
print(f"\nWrote {len(rows)} rows to {args.out}")
if __name__ == "__main__":
main()
A few design choices worth explaining:
-
srcsetis parsed, not matched. Asrcsetvalue is a comma-separated list of "URL width" pairs, so the script splits it and checks each URL. Apicture > sourcewithsrcsetis blockable by MDN's list, even when the fallback<img src>is fine, which is an easy one to miss by eye. -
<source>depends on its parent. Inside<audio>or<video>itssrcis upgradable; inside<picture>itssrcsetis blockable. The parser keeps a small stack to know which. -
@font-faceand@importare found first in<style>blocks and marked blockable, so they are not double-counted as genericcss_urlrows. -
Same-site matching treats
www.example.comandexample.comas the same host when it labels plain links as internal or external. -
--cafileexists for test servers with self-signed certificates, like the fixture below. On a real site you will not need it.
Running it against a test site
The fixture is a fictional tea shop with seven pages, served over HTTPS at https://localhost:8443 with a self-signed certificate, plus a tiny HTTP server on port 8080 that redirects to it. The sitemap lists nine URLs: the seven pages, one page that no longer exists (/old-offers) and one http:// URL left over from before the move. Problems were planted on five pages: an http:// image, srcset, iframe and video on the brewing guide; an http:// script, stylesheet and form action on the shop page; an inline background image, an @import, an @font-face and an image on a bare IP address on the about page; a mixed download and an <object> on the downloads page; and an http:// image and internal link on a contact page that sets upgrade-insecure-requests.
python3 mixed_content_audit.py https://localhost:8443/sitemap.xml --cafile cert.pem --out mixed_before.csv
Output:
Sitemap URLs: 9 pages with mixed content or http issues: 6
By flag:
blockable 7
clean 3
upgradable 3
insecure_form_action 1
css_url 1
blocked_ip_host 1
mixed_download 1
http_internal_link 1
http_404 1
sitemap_http_url 1
redirected 1
High severity:
/blog/brewing-guide picture>source http://cdn.harbortea.example/img/cups.webp
/blog/brewing-guide iframe http://video.harbortea.example/embed/abc123
/shop link[rel=stylesheet] http://fonts.typefoundry.example/css?family=Lora
/shop script http://widgets.reviewbox.example/embed.js
/shop form http://localhost:8443/cart/add
/about style @font-face http://fonts.typefoundry.example/brand.woff2
/about style @import http://cdn.harbortea.example/css/print.css
/about div[style] http://cdn.harbortea.example/img/harbor.jpg
/about img http://192.0.2.10/team.jpg
/downloads a[download] http://files.harbortea.example/wholesale-2026.pdf
/downloads object http://files.harbortea.example/menu.pdf
Wrote 21 rows to mixed_before.csv
A few rows from mixed_before.csv:
page,element,attribute,url,flag,severity,csp_upgrade,https_version
https://localhost:8443/about,style @font-face,url(),http://fonts.typefoundry.example/brand.woff2,blockable,high,no,
https://localhost:8443/about,style @import,url(),http://cdn.harbortea.example/css/print.css,blockable,high,no,
https://localhost:8443/about,div[style],url(),http://cdn.harbortea.example/img/harbor.jpg,css_url,high,no,
https://localhost:8443/about,img,src,http://192.0.2.10/team.jpg,blocked_ip_host,high,no,
https://localhost:8443/contact,a,href,http://localhost:8443/shipping,http_internal_link,low,yes,
https://localhost:8443/contact,img,src,http://cdn.harbortea.example/img/map.png,upgradable,medium,yes,
http://localhost:8080/shipping,,,,sitemap_http_url,medium,,
http://localhost:8080/shipping,,,https://localhost:8443/shipping,redirected,info,,
How to read this:
- Eleven high-severity rows on four pages. These are the ones a browser blocks or that send data over HTTP. On the real site, the shop page would lose its review widget script and its web font, and the brewing guide would show an empty frame where the video embed should be.
-
The
picture > sourcerow is blockable even though the<img>fallback inside the same<picture>uses a relative URL. Browsers that pick the WebP source would not load it. -
The bare IP image (
http://192.0.2.10/team.jpg) would have been upgradable on a hostname. On an IP address it is blocked. -
The contact page sets
upgrade-insecure-requests, so itshttp://map image is markedcsp_upgrade=yes. The browser will request it over HTTPS, and if the CDN does not serve that path over HTTPS, the image simply fails. The internalhttp://link is listed as low severity. -
The sitemap rows show the
http://localhost:8080/shippingentry being flagged, followed through its redirect, and the HTTPS page it lands on being audited and found clean. The/old-offersentry comes backhttp_404.
The run above was made without --check-https, because the fixture's third-party hosts (*.example) are made up and do not serve anything. On a real site, add the flag and sort the CSV by https_version: a 200 means a find and replace from http:// to https:// will work; anything else means you need to self-host, find another provider or remove the reference.
Fixing it and running again
The fix script applies what the report suggests: relative URLs for our own host, HTTPS for third-party hosts, a hostname instead of the bare IP, and a sitemap with only live HTTPS URLs.
"""Apply the fixes the audit suggests: https for third-party hosts, relative URLs for our own host,
a hostname instead of a bare IP, and a sitemap with only live https:// URLs."""
import pathlib, re
for p in pathlib.Path("site").rglob("*.html"):
s = p.read_text()
s = s.replace("http://localhost:8443/", "/") # own host: relative
s = s.replace("http://192.0.2.10/team.jpg", "/img/team.jpg") # bare IP: move to our host
s = re.sub(r"http://([a-z0-9.-]+\.example)/", r"https://\1/", s) # third parties: https
p.write_text(s)
sm = pathlib.Path("site/sitemap.xml")
lines = [l for l in sm.read_text().splitlines()
if "http://localhost:8080/" not in l and "/old-offers" not in l]
sm.write_text("\n".join(lines) + "\n")
print("fixed")
Second run:
python3 mixed_content_audit.py https://localhost:8443/sitemap.xml --cafile cert.pem --out mixed_after.csv
Sitemap URLs: 7 pages with mixed content or http issues: 0
By flag:
clean 7
High severity:
Wrote 7 rows to mixed_after.csv
Seven sitemap URLs, seven clean pages. On a real site, swapping http:// for https:// on a third-party host only works if that host serves the same file over HTTPS, which is what --check-https is for.
Running it on your own site
python3 mixed_content_audit.py https://www.example.com/sitemap.xml --check-https --hide-links --out mixed.csv
-
--hide-linksdrops plainhttp://<a>links, which are low severity, so the CSV holds only real mixed content and page-level problems. -
--workers 4is the default. Keep it low on shared hosting. - Sort the CSV by
severity, then byurl. The samehttp://script or font usually appears on every page that uses a template, so one fix in the theme often clears dozens of rows. - After a fix ships, run it again and keep both CSVs. The difference is your changelog.
What to fix first
-
insecure_form_actionandmixed_download. These involve visitor data and files people keep. -
blockablescripts and stylesheets. They are blocked, so something on the page is already broken. -
blocked_ip_hostandcss_url. Usually old theme code or hard-coded assets. -
upgradablemedia. Browsers upgrade them today, but they fail if the HTTPS version is missing, and MDN notes that "some upgradable content may become blockable in future." -
sitemap_http_urlandhttp_internal_link. Not mixed content, but they cost a redirect on every crawl and click.
If you rely on upgrade-insecure-requests while you clean up, remember MDN's two caveats: it does not upgrade navigational links to third-party sites, and it is not a replacement for HSTS.
Related free tools
If you only need to check the sitemap side before you run the script, two of our free tools can help: the Sitemap Finder and Checker reads robots.txt and the usual sitemap paths and reports which files load and how many URLs they list, and the Sitemap URL Extractor gives you one URL per line from a sitemap or sitemap index, which is a quick way to spot leftover http:// entries. Neither checks pages for mixed content; that is what the script is for.
FAQ
What is mixed content?
An HTTPS page that loads resources over HTTP. MDN describes it as "securely loaded web pages that use resources to be fetched via HTTP or another insecure protocol."
Which mixed content do browsers block?
Per MDN, browsers upgrade <img src>, audio and video to HTTPS and block everything else, including scripts, stylesheets, iframes, fonts, srcset and <picture> sources, objects and fetch() requests. Upgradable requests are blocked too if the host is an IP address.
Does upgrade-insecure-requests fix mixed content?
It makes the browser request http:// subresources over HTTPS, but MDN says the request "will fail without any fallback to HTTP" if the resource is not available over HTTPS. It is meant for sites with many legacy URLs, not as a permanent fix, and it does not replace HSTS.
Is a plain http:// link mixed content?
No. MDN says top-level navigation requests are not considered mixed content. For your own pages it still costs a redirect, so the script lists them as low severity.
Why does the script miss some mixed content my browser console shows?
It reads the HTML the server sends. Requests made by JavaScript after the page loads, and url() references inside external stylesheets, are not in that HTML. Check the browser console for those.
If you want to check your sitemaps before you run audits like this one, our free Sitemap Finder and Checker is a quick first step.
RG, Founder, Appie.run
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.