Back to cheatsheets
Web Security
Mixed Content Detection
Detect HTTP resources loaded on HTTPS pages and fix mixed-content warnings.
What you'll learn
- Check for mixed content
- Fix with upgrade-insecure-requests
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for mixed content detection. Click copy and paste into your project.
Check for mixed content
// Scan DOM for HTTP resources on HTTPS pages
function findMixedContent() {
const issues = [];
const protocol = location.protocol;
if (protocol !== 'https:') return issues;
// Check img, script, link, iframe, video, audio
const selectors = [
'img[src]', 'script[src]', 'link[href]',
'iframe[src]', 'video[src]', 'audio[src]',
'source[src]', 'object[data]'
];
document.querySelectorAll(selectors.join(','))
.forEach(el => {
const url = el.src || el.href || el.data;
if (url && url.startsWith('http:')) {
issues.push({
tag: el.tagName,
url: url,
type: el.tagName.toLowerCase()
});
}
});
return issues;
}
Fix with upgrade-insecure-requests
# CSP directive to auto-upgrade HTTP to HTTPS
Content-Security-Policy: upgrade-insecure-requests
# Nginx
add_header Content-Security-Policy
"upgrade-insecure-requests";
# This tells the browser to rewrite all HTTP
# resource requests to HTTPS automatically.
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site