How to allow http content within an iframe on a https site

后端 未结 10 1297
我寻月下人不归
我寻月下人不归 2020-11-22 14:06

I load some HTML into an iframe but when a file referenced is using http, not https, I get the following error:

[blocked] The page at {current_pagenam

相关标签:
10条回答
  • 2020-11-22 14:24

    Note: While this solution may have worked in some browsers when it was written in 2014, it no longer works. Navigating or redirecting to an HTTP URL in an iframe embedded in an HTTPS page is not permitted by modern browsers, even if the frame started out with an HTTPS URL.

    The best solution I created is to simply use google as the ssl proxy...

    https://www.google.com/search?q=%http://yourhttpsite.com&btnI=Im+Feeling+Lucky
    

    Tested and works in firefox.

    Other Methods:

    • Use a Third party such as embed.ly (but it it really only good for well known http APIs).

    • Create your own redirect script on an https page you control (a simple javascript redirect on a relative linked page should do the trick. Something like: (you can use any langauge/method)

      https://example.com That has a iframe linking to...

      https://example.com/utilities/redirect.html Which has a simple js redirect script like...

      document.location.href ="http://thenonsslsite.com";

    • Alternatively, you could add an RSS feed or write some reader/parser to read the http site and display it within your https site.

    • You could/should also recommend to the http site owner that they create an ssl connection. If for no other reason than it increases seo.

    Unless you can get the http site owner to create an ssl certificate, the most secure and permanent solution would be to create an RSS feed grabing the content you need (presumably you are not actually 'doing' anything on the http site -that is to say not logging in to any system).

    The real issue is that having http elements inside a https site represents a security issue. There are no completely kosher ways around this security risk so the above are just current work arounds.

    Note, that you can disable this security measure in most browsers (yourself, not for others). Also note that these 'hacks' may become obsolete over time.

    0 讨论(0)
  • 2020-11-22 14:28

    Using Google as the SSL proxy is not working currently,

    Why?

    If you opened any page from google, you will find there is a x-frame-options field in the header.

    The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a <frame>, <iframe> or <object>. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

    (Quote from MDN)

    One of the solution

    Below is my work around for this problem:

    Upload the content to AWS S3, and it will create a https link for the resource.
    Notice: set the permission to the html file for allowing everyone view it.

    After that, we can using it as the src of iframe in the https websites.

    0 讨论(0)
  • 2020-11-22 14:28

    All you need to do is just use Google as a Proxy server.

    https://www.google.ie/gwt/x?u=[YourHttpLink].

    <iframe src="https://www.google.ie/gwt/x?u=[Your http link]"></frame>
    

    It worked for me.

    Credits:- https://www.wikihow.com/Use-Google-As-a-Proxy

    0 讨论(0)
  • 2020-11-22 14:29

    You will always get warnings of blocked content in most browsers when trying to display non secure content on an https page. This is tricky if you want to embed stuff from other sites that aren't behind ssl. You can turn off the warnings or remove the blocking in your own browser but for other visitors it's a problem.

    One way to do it is to load the content server side and save the images and other things to your server and display them from https.

    You can also try using a service like embed.ly and get the content through them. They have support for getting the content behind https.

    0 讨论(0)
  • 2020-11-22 14:29

    Use your own HTTPS-to-HTTP reverse proxy.

    If your use case is about a few, rarely changing URLs to embed into the iframe, you can simply set up a reverse proxy for this on your own server and configure it so that one https URL on your server maps to one http URL on the proxied server. Since a reverse proxy is fully serverside, the browser cannot discover that it is "only" talking to a proxy of the real website, and thus will not complain as the connection to the proxy uses SSL properly.

    If for example you use Apache2 as your webserver, then see these instructions to create a reverse proxy.

    0 讨论(0)
  • 2020-11-22 14:30

    I know this is an old post, but another solution would be to use cURL, for example:

    redirect.php:

    <?php
    if (isset($_GET['url'])) {
        $url = $_GET['url'];
        $ch = curl_init();
        $timeout = 5;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $data = curl_exec($ch);
        curl_close($ch);
        echo $data;
    }
    

    then in your iframe tag, something like:

    <iframe src="/redirect.php?url=http://www.example.com/"></iframe>
    

    This is just a MINIMAL example to illustrate the idea -- it doesn't sanitize the URL, nor would it prevent someone else using the redirect.php for their own purposes. Consider these things in the context of your own site.

    The upside, though, is it's more flexible. For example, you could add some validation of the curl'd $data to make sure it's really what you want before displaying it -- for example, test to make sure it's not a 404, and have alternate content of your own ready if it is.

    Plus -- I'm a little weary of relying on Javascript redirects for anything important.

    Cheers!

    0 讨论(0)
提交回复
热议问题