在ASP.NET Core 2.2应用程序中,我们使用app.UseHsts();
启用了HSTS,它在响应头中添加了max-age
为30天的HSTS。
在提琴手中
Strict-Transport-Security: max-age=2592000
然后在Chrome中,如果我转到chrome://net-internals/#hsts
并查询我们的域名,则会得到:
发现:
static_sts_domain:
static_upgrade_mode: UNKNOWN
static_sts_include_subdomains:
static_sts_observed:
static_pkp_domain:
static_pkp_include_subdomains:
static_pkp_observed:
static_spki_hashes:
dynamic_sts_domain: subdomain.example.com //our domain name here
dynamic_upgrade_mode: FORCE_HTTPS
dynamic_sts_include_subdomains: false
dynamic_sts_observed: 1572023505.777819
dynamic_sts_expiry: 1574615505.777818
问题
dynamic_sts_observed
和dynamic_sts_expiry
的单位是什么。看起来好像不到几秒钟。值如何计算? https://subdomain.example.com
之类的子域,我们使用的SSL证书是通配符证书。 *.example.com
。因此,HSTS配置是否需要包括Subdomain?像Strict-Transport-Security: max-age=2592000, includeSubDomain
Unix纪元时间(即自1970年1月1日以来的秒数)。如Joachim的commebt所言,您可以在此处查看和转换它:https://www.unixtimestamp.com/index.php
是
好像您从未见过HSTS标头(即不会强制执行HTTPS)。
在下一次访问后,按照第2条,它是一个滑动到期日,每次访问时都会重新计算。
如果策略是顶级策略,那么您需要使用includeSubDomains
(请注意,如果您在问题中未填写,请加上S),以使其影响子域。您还可以在每个子域上发布单独的策略(相同或不同的策略)。仅当访问者访问该站点(例如https://example.com)时才加载顶级策略,因此,如果访问者仅访问子域(例如https://www.example.com),则浏览器将不会缓存该顶级策略。最佳做法是在所有策略上使用includeSubDomains
,并从顶级域中加载资产(例如单个像素或公司徽标),以强制采用该顶级策略,以便所有其他子域也受保护。仅当您没有任何仅使用HTTP的网站(例如http://intranet.example.com或http://blog.example.com)时,这种方法才有用,在这种情况下,您最好的做法是拥有一个没有includeSubDomains
的顶级策略,然后在每个策略上使用不同的策略完全支持includeSubDomains
的HTTPS的子域。该证书与HSTS没有任何关系(事实是每个受保护的域显然都需要一个证书!)。