What is a HSTS domain
.dev
域名已由 Google 纳入 HSTS 列表中,因此要求此域名的所有网站都必须加密,这表示所有网站都必须使用 HTTPS
HSTS是什么?
HTTP Strict Transport Security (HSTS: https://developer.mozilla.org/zh-CN/docs/Security/HTTP_Strict_Transport_Security
) 是一个安全功能,它告诉浏览器只能通过 HTTPS 访问当前资源,而不是 HTTP
这一机制可以在 HTTP 301 跳转到 HTTPS 之前先一步规避中间人攻击的风险。想想看,访问 http://example.com
的过程中是没有加密的,如果在这一阶段就搞事情的话,后果可想而知。
HSTS是怎么工作的?
当通过 HTTPS 访问你的站点的时候,你的服务器返回的时候加一个 Header,Strict-Transport-Security
,主要值是 max-age=xxx
。在设定好的时间内,所有对于当前域名的 HTTP 请求都自动转 HTTPS
细节可以参考 HTTP Strict Transport Security (https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Strict-Transport-Security
)
Strict-Transport-Security: max-age=<expire-time>
Strict-Transport-Security: max-age=<expire-time>; includeSubDomains
Strict-Transport-Security: max-age=<expire-time>; preload
那这和 .dev
.app
.page
等等域名有什么关系,前面说的 HSTS 列表又是什么?
HSTS列表是什么?
谷歌维护着一个 HSTS 预加载服务。按照如下指示成功提交你的域名后,浏览器将会永不使用非安全的方式连接到你的域名。虽然该服务是由谷歌提供的,但所有浏览器都有使用这份列表的意向(或者已经在用了)。但是,这不是 HSTS 标准的一部分,也不该被当作正式的内容。Chrome
& Chromium
的 HSTS 预加载列表: https://www.chromium.org/hsts
的 HSTS 预加载列表: nsSTSPreloadList.inc
另外我们可以通过 https://hstspreload.org/
来查询相关的域名是否在列表里,比如大家喜闻乐见的 example.com
Status: example.com is not preloaded.
而 hstspreload.org
显然是在这个列表里的
Status: hstspreload.org is currently preloaded.
在查询 .dev
可以看到整个 .dev
都是在列表里的,而查询 .com
.org
等普通的域名则会告诉你不要使用一个 . 开头的域名
.dev is currently preloaded
Status: .com is not preloaded.
提交域名到HSTS预加载列表
还是通过 https://hstspreload.org/
,有说明如何提交域名到 Chrome
的 HSTS Preload List.
服务端需要配置 SSL 证书,将 HTTP 请求重定向到 HTTPS,提供 HSTS Header,并且max-age
足够长,然后申请就就可以了。
通过 CloudFlare 托管的域名可以自助设置 HSTS Enable
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.me
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No privacy information is collected here