Blog | G5 Cyber Security

HTTPS iframe on HTTP: Security Risks & Fixes

TL;DR

Embedding an HTTPS iframe (like a YouTube video or Google Map) on an insecure HTTP page creates mixed content issues. This weakens your cyber security, can cause browser warnings, and potentially allows attackers to tamper with the iframe’s contents. The best fix is to move your entire site to HTTPS.

Understanding the Problem

When you load a webpage over HTTP (no encryption), any content loaded from an HTTPS source (encrypted) is considered ‘mixed content’. Browsers are increasingly strict about this because it introduces vulnerabilities. Here’s why:

Step-by-Step Solutions

  1. The Best Solution: Move Your Entire Site to HTTPS
    • This is the most secure and recommended approach. It encrypts all communication between your server and users’ browsers, eliminating mixed content issues entirely.
    • You’ll need an SSL/TLS certificate (Let’s Encrypt offers free certificates).
    • Configure your web server (Apache, Nginx, etc.) to use the certificate. The exact steps depend on your server software.
  2. If You *Cannot* Move to HTTPS Immediately: Content Security Policy (CSP)

    Content Security Policy allows you to control which resources the browser is allowed to load for your page. It’s a more complex solution, but can help mitigate risks if you’re stuck with HTTP.

    • Add a CSP Header: You need to add an HTTP response header telling the browser what to allow.
      Content-Security-Policy: upgrade-insecure-requests

      This tells the browser to automatically upgrade all insecure (HTTP) requests to HTTPS where possible. It won’t *force* HTTPS, but it will try.

    • Specific Resource Allowances: If you need to allow specific HTTP resources that can’t be upgraded, you can explicitly list them.
      Content-Security-Policy: upgrade-insecure-requests; script-src 'self' https://example.com

      This allows scripts from your own domain and `https://example.com`.

    • Testing CSP: Use a CSP testing tool (like CSP Evaluator) to ensure your policy doesn’t break anything on your site.
  3. Avoid Mixed Content Where Possible
    • Replace HTTP Resources: If you can find HTTPS equivalents for any resources loaded over HTTP, use them instead.
    • Self-Host Assets: Consider hosting assets (images, scripts) yourself to avoid relying on external HTTP sources.

Checking for Mixed Content

You can use browser developer tools to identify mixed content issues:

Important Considerations

Exit mobile version