[GH-ISSUE #2899] [Feature Request] HSTS support #2313

Closed
opened 2026-05-05 13:29:30 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @donargreys on GitHub (Apr 18, 2022).
Original GitHub issue: https://github.com/fatedier/frp/issues/2899

Describe the feature request

HSTS 工作原理
通常,当您在 Web 浏览器中输入 URL 时,您会跳过协议部分。 例如,你输入的是 www.acunetix.com,而不是 http://www.acunetix.com。 在这种情况下,浏览器假设你想使用 HTTP 协议,所以它在这个阶段发出一个 HTTP 请求 到 www.acunetix.com,同时,Web Server 会返回 301 状态码将请求重定向到 HTTPS 站点。 接下来浏览器使用 HTTPS 连接到 www.acunetix.com。 这时 HSTS 安全策略保护开始使用 HTTP 响应头:

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
响应头的 Strict-Transport-Security 给浏览器提供了详细的说明。 从现在开始,每个连接到该网站及其子域的下一年(31536000秒)从这个头被接收的时刻起必须是一个 HTTPS 连接。 HTTP 连接是完全不允许的。 如果浏览器接收到使用 HTTP 加载资源的请求,则必须尝试使用 HTTPS 请求替代。 如果 HTTPS 不可用,则必须直接终止连接。

此外,如果证书无效,将阻止你建立连接。 通常来说,如果 HTTPS 证书无效(如:过期、自签名、由未知 CA 签名等),浏览器会显示一个可以规避的警告。 但是,如果站点有 HSTS,浏览器就不会让你绕过警告。 若要访问该站点,必须从浏览器内的 HSTS 列表中删除该站点。

响应头的 Strict-Transport-Security 是针对一个特定的网站发送的,并且覆盖一个特定的域名(domain)。 因此,如果你有 HSTS 的 www.acunetix.com ,它不会覆盖 acunetix. com,而只覆盖 www 子域名。 这就是为什么,为了完全的保护,你的网站应该包含一个对 base domain 的调用(在本例中是 acunetix. com) ,并且接收该域名的 Strict-Transport-Security 头和 includeSubDomains 指令。

Describe alternatives you've considered

for now ,https2https plugin works fine

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @donargreys on GitHub (Apr 18, 2022). Original GitHub issue: https://github.com/fatedier/frp/issues/2899 ### Describe the feature request HSTS 工作原理 通常,当您在 Web 浏览器中输入 URL 时,您会跳过协议部分。 例如,你输入的是 www.acunetix.com,而不是 http://www.acunetix.com。 在这种情况下,浏览器假设你想使用 HTTP 协议,所以它在这个阶段发出一个 [HTTP 请求](https://www.acunetix.com/blog/articles/http-security-introduction-to-http-part-1/) 到 www.acunetix.com,同时,Web Server 会返回 301 状态码将请求重定向到 HTTPS 站点。 接下来浏览器使用 HTTPS 连接到 www.acunetix.com。 这时 HSTS 安全策略保护开始使用 HTTP 响应头: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload 响应头的 Strict-Transport-Security 给浏览器提供了详细的说明。 从现在开始,每个连接到该网站及其子域的下一年(31536000秒)从这个头被接收的时刻起必须是一个 HTTPS 连接。 HTTP 连接是完全不允许的。 如果浏览器接收到使用 HTTP 加载资源的请求,则必须尝试使用 HTTPS 请求替代。 如果 HTTPS 不可用,则必须直接终止连接。 此外,如果证书无效,将阻止你建立连接。 通常来说,如果 HTTPS 证书无效(如:过期、自签名、由未知 CA 签名等),浏览器会显示一个可以规避的警告。 但是,如果站点有 HSTS,浏览器就不会让你绕过警告。 若要访问该站点,必须从浏览器内的 HSTS 列表中删除该站点。 响应头的 Strict-Transport-Security 是针对一个特定的网站发送的,并且覆盖一个特定的域名(domain)。 因此,如果你有 HSTS 的 www.acunetix.com ,它不会覆盖 acunetix. com,而只覆盖 www 子域名。 这就是为什么,为了完全的保护,你的网站应该包含一个对 base domain 的调用(在本例中是 acunetix. com) ,并且接收该域名的 Strict-Transport-Security 头和 includeSubDomains 指令。 ![](https://pic1.zhimg.com/v2-ae9f8ef4007bf90220f91a4e5a39c594_r.jpg) ### Describe alternatives you've considered for now ,https2https plugin works fine ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [X] Security - [X] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [X] Client Plugin - [X] Server Plugin - [ ] Extensions - [ ] Others
gitea-mirror 2026-05-05 13:29:30 -06:00
Author
Owner

@Becods commented on GitHub (Apr 25, 2022):

首先结论:没有必要

可以手动在frpc端实现

Rewriting the HTTP Host Header

# frpc.ini
[web]
type = http
local_port = 80
custom_domains = test.example.com
header_Strict-Transport-Security = "max-age=63072000; includeSubdomains; preload"
<!-- gh-comment-id:1108485580 --> @Becods commented on GitHub (Apr 25, 2022): 首先结论:**没有必要** 可以手动在frpc端实现 [Rewriting the HTTP Host Header](https://github.com/fatedier/frp#rewriting-the-http-host-header) ``` # frpc.ini [web] type = http local_port = 80 custom_domains = test.example.com header_Strict-Transport-Security = "max-age=63072000; includeSubdomains; preload" ```
Author
Owner

@donargreys commented on GitHub (Apr 28, 2022):

不可行。
理论上,这个是重写request header,而不是response header。
实践上,也在服务器上试过了,不行

p.s. 正常来说,可以在承接frp的后端服务器上完成设置,问题是我用的群晖改起来比较麻烦。

<!-- gh-comment-id:1111808917 --> @donargreys commented on GitHub (Apr 28, 2022): > 不可行。 理论上,这个是重写request header,而不是response header。 实践上,也在服务器上试过了,不行 p.s. 正常来说,可以在承接frp的后端服务器上完成设置,问题是我用的群晖改起来比较麻烦。
Author
Owner

@github-actions[bot] commented on GitHub (May 29, 2022):

Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.

<!-- gh-comment-id:1140350061 --> @github-actions[bot] commented on GitHub (May 29, 2022): Issues go stale after 30d of inactivity. Stale issues rot after an additional 7d of inactivity and eventually close.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#2313
No description provided.