在没有浏览器头部的情况下请求 url 时,HSTS 的行为如何

How does HSTS behaves when a url is requested without a browser head

作为安全改进的一部分,我们正在研究安全性 header 并添加了 HTTP headers,包括 HSTS or Strict-Transport-Security。 header 只是强制浏览器使用域的 https 版本,即使您请求 http 版本也是如此。如文档中所述,工作方式如下,

The first time your site is accessed using HTTPS and it returns the Strict-Transport-Security header, the browser records this information, so that future attempts to load the site using HTTP will automatically use HTTPS instead.

我们的一些托管服务将在没有浏览器头的情况下调用。这可能来自另一个用 Java 编写的应用程序。假设客户端调用其中一项服务 http。现在,在这种情况下,HSTS headers 将如何处理?它会重定向到基于 https 的服务还是会继续使用 http 服务?

这完全取决于客户。我想只有浏览器会实现 HSTS,因为它是为了防止人们使用错误的 URLs 而 non-browsers 通常由理解 URL 的更多技术用户使用。

Let's say a client calls one of the services http. Now, in this case how is the HSTS headers will be treated? will it redirect to the https based services or will it continue using the http one?

您误解了 HSTS 的基本工作原理。首先,不应为 HTTP 请求发送 HSTS,而应仅为 HTTPS 请求发送。这是一种安全保护措施,可防止有人通过添加 HSTS header 对 HTTP-only 站点进行 DoSing(因为 HTTP 流量不安全并且可以在途中更改 - 与 HTTPS 流量不同)。因此初始 HTTP 请求不会被重定向,因此不会获取 HSTS header。使用 HSTS 重定向很重要。