关于浏览器HTTPS Upgrade

Chrome

在Chrome浏览器中,如果你没有在浏览器地址框中输入协议,就会首先尝试HTTPS,如果3秒内没有收到响应,就会迅速发送一个HTTP请求。
chrome://settings/security 中有一个选项(设置-隐私设置和安全性-安全-一律使用安全连接)Always use secure connections:
Upgrade navigations to HTTPS and warn you before loading sites that don't support it
如果开启了这个配置,会自动将连接协议升级到HTTPS,并在加载不支持HTTPS的网站之前向您发出警告。

Edge

Edge也在试验一个类似的特性称为Automatic HTTPS,当你在地址栏输入一个URL或者点击一个跳转到新站点的连接,它会检查是否将你的连接切换为HTTPS。
除了安全性,用户首要关心的还有生产效率和性能。开启这一特性,在默认情况下只会对那些有很大可能支持HTTPS的域名(HTTPS-capable domains)进行连接升级。限定HTTPS-capable domains减少了连接失败,以及先尝试HTTPS然后回退到HTTP所带来的潜在的性能与可靠性问题。
这一特性的默认状态是default,由于是试验特性,它并不会在edge://settings/privacy ,即(设置-隐私、搜索和服务-安全性)里显示,可以通过访问edge://flags/#edge-automatic-HTTPS 来开启。开启之后就会在安全性那里显示两个选项:

  • Switch to HTTPS only on websites likely to support HTTPS
  • Always switch from HTTP to HTTPS(connection errors might occur more often)

The known-capable domains list

HTTPS-capable domains 列表通过浏览器组件传递到用户设备上,该组件名为Automatic HTTPS Lists,如果没有在edge://components/中展示,可以在C:\Users\你的用户名\AppData\Local\Microsoft\Edge\User Data\HTTPS Upgrade Lists发现它的存在。
Microsoft根据顶级域名接收的流量中htpps占很大比率,但却没有配置为需要HTTPS(即domains that are not already included in HSTS Preload Lists 这个后面再说)的域名来生成这个列表。
ps: cn顶级域名在中国,微软应该分析不到吧。
有些用户喜欢使用HTTPS访问所有连接,并且能够接受频繁出现的安全警告页面(这些页面使你能够尝试使用HTTP访问相同的URL)。
无论配置Automatic HTTPS为known-capable或all domains,这一特性会本地缓存最近访问失败的域名,当你下次访问已经缓存的站点时,Automatic HTTPS就会跳过升级尝试来避免重复的警告页面,使你专注于浏览。
用户可以访问edge://settings/privacy ,通过清除浏览历史来清除这个缓存。在InPrivate会话下访问的缓存会在关闭时自动清除。

子资源升级

最好将所有资源都使用HTTPS协议传输,而不仅仅是地址栏中URL对应的文档。活动/主动内容子资源(active content subresources)能够访问你正在访问页面的一些或者全部内容,如果这些资源使用HTTP传输,攻击者仍然有可能操纵页面内容。同时,如果将这些不支持HTTPS的子资源切换到HTTPS,会潜在地导致其它错误。

  • 当配置Automatic HTTPS为known-capable domains时,它将升级host相同的活动子资源到HTTPS。例如,在 http://shelterofly.cn 页面,http://shelterofly.cn/script.js 会被升级,但是http://subdomain.shelterofly.cn/script.js 和 http://baidu.com/script.js 不会被升级。特性支持的Active content subresources见下面的Active content list。
  • always switch配置用来提高安全性,所有的Active content subresources都会被升级。加载资源失败(以及因此造成的站点损坏)可能会更常见。

Mixed content

Mixed content指一个HTTPS页面里面含有使用HTTP协议来获取的内容。它又分为mixed passive/display content和mixed active content。这二者的区别在于最坏情况下的威胁等级不同。被动内容的威胁等级较低(可能含有误导信息或者用户cookies被窃取),而主动内容则可能导致网络钓鱼、敏感信息泄露以及重定向到恶意网站等。

Passive content list:

  • <img> (src attribute)
  • <audio> (src attribute)
  • <video> (src attribute)
  • <object> subresources (when an <object> performs HTTP requests)

Active content list:

  • <script> (src attribute)
  • <link> (href attribute) (this includes CSS stylesheets)
  • <iframe> (src attribute)
  • XMLHttpRequest requests
  • fetch() requests
  • All cases in CSS where a url() value is used (@font-face, cursor, background-image, and so forth).
  • <object> (data attribute)
  • Navigator.sendBeacon (url attribute)

开发者守则

推荐将所有资源都使用HTTPS传输,包括顶级文档以及任何子资源。开发者也需要考虑将它们的站点配置为需要HTTPS,尽管这可能不适用于所有的域名。
如果你还没有这样配置域名,可以在你的网站上观察Automatic HTTPS产生的效果。按F12打开开发者工具,打开控制台-设置-开启 保留日志 选项。当Automatic HTTPS将你的连接切换到HTTPS时,控制台中会出现一条信息:

Scenario Console Message
The document switched to HTTPS, but no subresources were upgraded Automatic HTTPS switched your connection to HTTPS.
The document switched to HTTPS, and same-host active subresources were upgraded because Automatic HTTPS is set to "upgrade on websites likely to support HTTPS" Automatic HTTPS switched your connection and same-host subresources to HTTPS.
The document switched to HTTPS, and all active subresources were upgraded because Automatic HTTPS is set to "always switch" Automatic HTTPS switched your connection and subresources to HTTPS.

参考资料:

https://blogs.windows.com/msedgedev/2021/06/01/available-for-preview-automatic-https-helps-keep-your-browsing-more-secure/