Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Halo默认开启HSTS导致未设置SSL证书的其他二级域名无法正常访问 #4943

Closed
caneman opened this issue Nov 29, 2023 · 5 comments · Fixed by #5956
Closed

Halo默认开启HSTS导致未设置SSL证书的其他二级域名无法正常访问 #4943

caneman opened this issue Nov 29, 2023 · 5 comments · Fixed by #5956
Assignees
Labels
area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement.
Milestone

Comments

@caneman
Copy link

caneman commented Nov 29, 2023

系统信息

Halo版本: 2.10

部署方式: docker

网络拓扑: halo、nginx、web2同属一个Network

Nginx相关配置

server {
    listen 80;
    server_name xx.com;
    rewrite ^(.*) https://xx.com$1 permanent;
}

server {
    listen 443 ssl;
    server_name  xx.com;

    ssl_certificate /etc/nginx/ssl/xx.com.pem;
    ssl_certificate_key /etc/nginx/ssl/xx.com.key;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_pass http://halo:8090;
        proxy_set_header HOST $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

# Web2
server {
    listen 80;
    server_name a.xx.com;
    location / {
        proxy_pass http://web2:8080;
    }
}

使用的哪种方式运行?

Docker

在线站点地址

No response

发生了什么?

主域名 xx.com(halo,设置了SSL证书),a.xx.com(另一个web站点,未设置SSL证书)。

因Halo默认响应头设置了: Strict-Transport-Security: max-age=31536000 ; includeSubDomains
(当浏览器访问网站时,HSTS 会强制浏览器仅通过安全的 HTTPS 连接与该网站通信,即使用户尝试通过 HTTP 访问)

导致当访问过 xx.com(halo主站)后,所有的未设置 ssl 的二级域名都会爆「NET::ERR_CERT_COMMON_NAME_INVALID」错误(域名与证书不匹配)。

原因在于,由于halo的响应头设置,会导致访问 a.xx.com,也强制走https,又因为a.xx.com没有证书,而Nginx 在处理没有配置SSL的HTTPS 请求时会默认到另一个具有 SSL 配置的服务器块(xx.com的证书)。而浏览器判定证书(xx.com)和域名(a.xx.com)不匹配,报错。

经实验以下方案均不奏效

  1. 在 nginx 配置中将 a.xx.com 443端口转发到80端口,失败
  2. 设置全局的443端口默认关闭,失败
server {
    listen 443 ssl default_server;
    server_name _;

    ssl_certificate /path/to/default/cert.pem;
    ssl_certificate_key /path/to/default/key.pem;

    return 444; # 关闭连接
}

可以稳定复现

xx.com(halo,设置了SSL)
a.xx.com(未设置SSL)
b.xx.com(设置SSL)
c.xx.com(未设置SSL)

清除浏览器缓存

a、b、c 任意次序、任意次数访问均正常,一旦访问主站 xx.com(halo), 再次访问 a、c 即报错,b不受影响。

相关日志输出

No response

附加信息

No response

@caneman
Copy link
Author

caneman commented Nov 29, 2023

这个影响范围还是比较广的,只要开了 Halo,其他所有二级域名必需设置证书。

通过在 Nginx 的 Halo 部分单独配置 proxy_hide_header Strict-Transport-Security; 可以实现去除这个 Header 的效果,但是还是希望默认不要带,或者至少去除「includeSubDomains」,再或者改成可选项不要开启也行。

@ruibaby
Copy link
Member

ruibaby commented Nov 30, 2023

cc @halo-dev/sig-halo

@JohnNiang
Copy link
Member

Hi @caneman ,建议移除掉这一行:

proxy_set_header X-Forwarded-Proto $scheme;

如果 Halo 检测到 HTTP scheme 是 https 则会自动添加上响应头 Strict-Transport-Security

/kind support

@f2c-ci-robot f2c-ci-robot bot added the kind/support Categorizes issue or PR as a support question. label Nov 30, 2023
@caneman caneman closed this as completed Dec 1, 2023
@Asteri5m
Copy link

Hi @caneman ,建议移除掉这一行:

proxy_set_header X-Forwarded-Proto $scheme;

如果 Halo 检测到 HTTP scheme 是 https 则会自动添加上响应头 Strict-Transport-Security

/kind support

我今天在创建halo博客的时候碰到了同样的问题,最后只能通过给子域名配置证书来解决。
关于你说的移除掉这一行,既然官方推荐中给出了这一行,那么移除这一行是否会造成其他的影响,插件或者是halo本身。

@JohnNiang
Copy link
Member

Hi @Asteri5m , 感谢反馈!

目前,移除这一行不会对 Halo 产生影响。不过可以考虑在 Halo 侧默认不配置响应头 Strict-Transport-Security 的 includeSubDomains 参数。

/kind improvement
/area core
/milestone 2.16.x
/remove-kind support

@f2c-ci-robot f2c-ci-robot bot added this to the 2.16.x milestone May 20, 2024
@f2c-ci-robot f2c-ci-robot bot added kind/improvement Categorizes issue or PR as related to a improvement. area/core Issues or PRs related to the Halo Core and removed kind/support Categorizes issue or PR as a support question. labels May 20, 2024
@JohnNiang JohnNiang reopened this May 20, 2024
@JohnNiang JohnNiang self-assigned this May 20, 2024
f2c-ci-robot bot pushed a commit that referenced this issue May 21, 2024
#### What type of PR is this?

/kind improvement
/area core
/milestone 2.16.x

#### What this PR does / why we need it:

This PR ignores `includeSubdomains` for HSTS header. See #4943 for more.

#### Which issue(s) this PR fixes:

Fixes #4943

#### Does this PR introduce a user-facing change?

```release-note
修复开启 HSTS 可能会导致未开启 HSTS 的子域名站点无法访问的问题
```
@ruibaby ruibaby modified the milestones: 2.16.x, 2.16.0 May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants