The unencrypted HTTP content on the secured web pages could be accessed by hackers as well as could be modified by Man-in-the-Middle (MITM) attackers, which results in unsecured connection. This behavior of web pages is called a mixed content page.
因为工作中突然遇到了,就简单看了一下这些内容。希望能够起到抛砖引玉的效果。
在下面的链接中:
https://segmentfault.com/q/1010000005872734,博主引出了两个问题:
1. HTTPS页面里动态的引入HTTP资源,比如引入一个js文件,会被直接block掉的
2. 在HTTPS页面里通过AJAX的方式请求HTTP资源,也会被直接block掉的。
下面是具体的错误提示:
Mixed Content: The page at 'https://url_1' was loaded over HTTPS,
but requested an insecure script 'http://monitor_analytic.js'.
This request has been blocked; the content must be served over HTTPS.
提出的解决办法:
方法1:相对协议。
对于同时支持HTTPS和HTTP的资源,引用的时候要把引用资源的URL里的协议头去掉,
浏览器会自动根据当前是HTTPS还是HTTP来给资源URL补上协议头的,可以达到无缝切换。
下面是回答中有人给出的解决办法:http://thehackernews.com
The search engine giant recommended you to enable it via an HTTP response header,
"Content-Security-Policy: upgrade-insecure-requests," if all the content is controlled by you.
However, if the unsecure resources are served from a web server you don’t control, you can include the
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> tag in your page's <head>.
对于https协议下访问http的图片链接,chrome浏览器并没有block,而是提出了警告。但是并不是所有手机的webkit浏览器都支持这样的警告,很多手机可能还是会直接block,造成图片没有办法显示。
Mixed Content: The page at 'https://url_1' was loaded over HTTPS, but requested an insecure image
'http://762961797.jpg'. This content should also be served over HTTPS.
总结:对于mixed content page that the connection is only partially encrypted. 为了在http转https的过程中顺利过渡,mixed content page页面是非常糟糕的选择。
如果觉得有用,请关注我的公众号,谢谢大家!